|
@@ -15,6 +15,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.ModelMap;
|
|
import org.springframework.ui.ModelMap;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -23,6 +24,7 @@ import com.itstyle.common.constants.Constants;
|
|
import com.itstyle.common.model.Product;
|
|
import com.itstyle.common.model.Product;
|
|
import com.itstyle.modules.weixinpay.service.IWeixinPayService;
|
|
import com.itstyle.modules.weixinpay.service.IWeixinPayService;
|
|
import com.itstyle.modules.weixinpay.util.ConfigUtil;
|
|
import com.itstyle.modules.weixinpay.util.ConfigUtil;
|
|
|
|
+import com.itstyle.modules.weixinpay.util.HttpUtil;
|
|
import com.itstyle.modules.weixinpay.util.PayCommonUtil;
|
|
import com.itstyle.modules.weixinpay.util.PayCommonUtil;
|
|
import com.itstyle.modules.weixinpay.util.XMLUtil;
|
|
import com.itstyle.modules.weixinpay.util.XMLUtil;
|
|
|
|
|
|
@@ -38,6 +40,9 @@ public class WeixinPayController {
|
|
@Autowired
|
|
@Autowired
|
|
private IWeixinPayService weixinPayService;
|
|
private IWeixinPayService weixinPayService;
|
|
|
|
|
|
|
|
+ @Value("${wexinpay.notify.url}")
|
|
|
|
+ private String notify_url;
|
|
|
|
+
|
|
@RequestMapping("/index")
|
|
@RequestMapping("/index")
|
|
public String index() {
|
|
public String index() {
|
|
return "weixinpay/index";
|
|
return "weixinpay/index";
|
|
@@ -132,4 +137,99 @@ public class WeixinPayController {
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
|
|
+ * 模式一支付回调URL(生成二维码见 qrCodeUtil)
|
|
|
|
+ * 商户支付回调URL设置指引:进入公众平台-->微信支付-->开发配置-->扫码支付-->修改
|
|
|
|
+ * @Author 科帮网
|
|
|
|
+ * @param request
|
|
|
|
+ * @param response
|
|
|
|
+ * @throws Exception void
|
|
|
|
+ * @Date 2017年8月3日
|
|
|
|
+ * 更新日志
|
|
|
|
+ * 2017年8月3日 科帮网 首次创建
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ @SuppressWarnings({ "unchecked", "rawtypes"})
|
|
|
|
+ @RequestMapping(value = "bizpayurl")
|
|
|
|
+ public void bizpayurl(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
|
+ logger.info("模式一支付回调URL");
|
|
|
|
+ //读取参数
|
|
|
|
+ InputStream inputStream = request.getInputStream();
|
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
|
+ String s;
|
|
|
|
+ BufferedReader in = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
|
|
|
+ while ((s = in.readLine()) != null) {
|
|
|
|
+ sb.append(s);
|
|
|
|
+ }
|
|
|
|
+ in.close();
|
|
|
|
+ inputStream.close();
|
|
|
|
+
|
|
|
|
+ //解析xml成map
|
|
|
|
+ Map<String, String> map = XMLUtil.doXMLParse(sb.toString());
|
|
|
|
+ //过滤空 设置 TreeMap
|
|
|
|
+ SortedMap<Object, Object> packageParams = new TreeMap<Object, Object>();
|
|
|
|
+ Iterator it = map.keySet().iterator();
|
|
|
|
+ while (it.hasNext()) {
|
|
|
|
+ String parameter = (String) it.next();
|
|
|
|
+ String parameterValue = map.get(parameter);
|
|
|
|
+
|
|
|
|
+ String v = "";
|
|
|
|
+ if (null != parameterValue) {
|
|
|
|
+ v = parameterValue.trim();
|
|
|
|
+ }
|
|
|
|
+ packageParams.put(parameter, v);
|
|
|
|
+ }
|
|
|
|
+ //判断签名是否正确
|
|
|
|
+ if (PayCommonUtil.isTenpaySign("UTF-8", packageParams, ConfigUtil.API_KEY)) {
|
|
|
|
+ //统一下单
|
|
|
|
+ SortedMap<Object, Object> params = new TreeMap<Object, Object>();
|
|
|
|
+ ConfigUtil.commonParams(params);
|
|
|
|
+ //随即生成一个 入库 走业务逻辑
|
|
|
|
+ String out_trade_no=Long.toString(System.currentTimeMillis());
|
|
|
|
+ params.put("body", "模式一扫码支付");// 商品描述
|
|
|
|
+ params.put("out_trade_no", out_trade_no);// 商户订单号
|
|
|
|
+ params.put("total_fee", "100");// 总金额
|
|
|
|
+ params.put("spbill_create_ip", "192.168.1.66");// 发起人IP地址
|
|
|
|
+ params.put("notify_url", notify_url);// 回调地址
|
|
|
|
+ params.put("trade_type", "NATIVE");// 交易类型
|
|
|
|
+
|
|
|
|
+ String paramsSign = PayCommonUtil.createSign("UTF-8", params, ConfigUtil.API_KEY);
|
|
|
|
+ params.put("sign", paramsSign);// 签名
|
|
|
|
+ String requestXML = PayCommonUtil.getRequestXml(params);
|
|
|
|
+
|
|
|
|
+ String resXml = HttpUtil.postData(ConfigUtil.UNIFIED_ORDER_URL, requestXML);
|
|
|
|
+ Map<String, String> payResult = XMLUtil.doXMLParse(resXml);
|
|
|
|
+ String returnCode = (String) payResult.get("return_code");
|
|
|
|
+ if("SUCCESS".equals(returnCode)){
|
|
|
|
+ String resultCode = (String) payResult.get("result_code");
|
|
|
|
+ if("SUCCESS".equals(resultCode)){
|
|
|
|
+ logger.info("(订单号:{}生成微信支付码成功)",out_trade_no);
|
|
|
|
+
|
|
|
|
+ String prepay_id = payResult.get("prepay_id");
|
|
|
|
+ SortedMap<Object, Object> prepayParams = new TreeMap<Object, Object>();
|
|
|
|
+ ConfigUtil.commonParams(params);
|
|
|
|
+ prepayParams.put("prepay_id", prepay_id);
|
|
|
|
+ prepayParams.put("return_code", "SUCCESS");
|
|
|
|
+ prepayParams.put("result_code", "SUCCESS");
|
|
|
|
+ String prepaySign = PayCommonUtil.createSign("UTF-8", prepayParams, ConfigUtil.API_KEY);
|
|
|
|
+ prepayParams.put("sign", prepaySign);
|
|
|
|
+ String prepayXml = PayCommonUtil.getRequestXml(prepayParams);
|
|
|
|
+
|
|
|
|
+ //通知微信 预下单成功
|
|
|
|
+ BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
|
|
|
|
+ out.write(prepayXml.getBytes());
|
|
|
|
+ out.flush();
|
|
|
|
+ out.close();
|
|
|
|
+ }else{
|
|
|
|
+ String errCodeDes = (String) map.get("err_code_des");
|
|
|
|
+ logger.info("(订单号:{}生成微信支付码(系统)失败[{}])",out_trade_no,errCodeDes);
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ String returnMsg = (String) map.get("return_msg");
|
|
|
|
+ logger.info("(订单号:{} 生成微信支付码(通信)失败[{}])",out_trade_no,returnMsg);
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ logger.info("签名错误");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|