版权声明:疏影横斜灬水清浅 https://blog.csdn.net/Goligory/article/details/80031287
参考大神的工具,大家可以看过来:https://blog.csdn.net/zyw_java/article/details/54024162
一些基本的设置可以参考我这篇h5支付,这里不做赘述:https://blog.csdn.net/goligory/article/details/78392505
<dependency>
<groupId>com.github.javen205</groupId>
<artifactId>IJPay</artifactId>
<version>1.0</version>
</dependency>
上代码:
public WxPayApiConfig getApiConfig() {
return WxPayApiConfig.New()
.setAppId(configBean.getWxAppId())
.setMchId(configBean.getWxMchId())
.setPaternerKey(configBean.getWxPartnerKey())
.setPayModel(WxPayApiConfig.PayModel.BUSINESSMODEL);
}
/**
* 扫码支付模式二
* 已测试
*/
@RequestMapping(value ="/codePay.do",method = {RequestMethod.POST,RequestMethod.GET})
public ModelAndView scanCode2(HttpServletRequest request,HttpServletResponse response,
@RequestParam("total_fee") String total_fee) {
ModelAndView mv = new ModelAndView();
String openId="o6L670YbTF929Qdf-e-ehARR_p-k";
if (StrKit.isBlank(openId)) {
System.out.println("openid为空");
return mv;
}
if (StrKit.isBlank(total_fee)) {
System.out.println("支付金额不能为空");
return mv;
}
String ip = IpKit.getRealIp(request);
if (StrKit.isBlank(ip)) {
ip = "127.0.0.1";
}
System.out.println("ip:"+ip);
WxPayApiConfigKit.putApiConfig(getApiConfig());
Map<String, String> params = WxPayApiConfigKit.getWxPayApiConfig()
.setAttach("IJPay 测试 -By Javen")
.setBody("IJPay 扫码支付2测试 -By Javen")
.setOpenId(openId)
.setSpbillCreateIp(ip)
.setTotalFee(total_fee)
.setTradeType(WxPayApi.TradeType.NATIVE)
.setNotifyUrl(notify_url)
.setOutTradeNo(String.valueOf(System.currentTimeMillis()))
.build();
String xmlResult = WxPayApi.pushOrder(false,params);
System.out.println("xmlResult:"+xmlResult);
Map<String, String> resultMap = PaymentKit.xmlToMap(xmlResult);
System.out.println("解析resultMap:"+resultMap);
String return_code = resultMap.get("return_code");
String return_msg = resultMap.get("return_msg");
if (!PaymentKit.codeIsOK(return_code)) {
System.out.println("error:"+return_msg);
return mv;
}
String result_code = resultMap.get("result_code");
if (!PaymentKit.codeIsOK(result_code)) {
return mv;
}
//生成预付订单success
String qrCodeUrl = resultMap.get("code_url");
System.out.println("codeurl链接:"+qrCodeUrl);
mv.addObject("codeUrl",qrCodeUrl);
mv.setViewName("Qrcode");
return mv;
}
这个是原来的请求方式,大家可以自行按照自己的方式更改成restful形式的,最后生成qrCodeUrl,将其返回给前端生成二维码即可,回调在在h5支付那篇文章中
其他的jar如果找不到去这里看一下,这是h5支付和公众号支付,把扫码支付集成进去就行:http://download.csdn.net/download/goligory/10044575