springboot 实现微信小程序(微信支付)
官方文档 https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1
申请微信支付前先去申请好微信商户号 https://pay.weixin.qq.com/index.php/core/home/login?return_url=%2F
在微信支付里(查看商户号 - 下载相关证书 - 设置key)在以下会用到
public Map<String String>payment(String orderNum){ System.out.println("【小程序支付】 统一下单开始, 订单金额"+countsum); SortedMap<String, String> resultMap = new TreeMap<String, String>(); Wxchatpayconfig wxchatpayconfig = new Wxchatpayconfig(); Map<String,String> resMap = this.xcxUnifieldOrder(orderNum, Wxchatpayconfig.TRADE_TYPE_JSAPI, countsum,openId); if(SUCCESS.equals(resMap.get("return_code")) && SUCCESS.equals(resMap.get("result_code"))){ resultMap.put("appId", wxchatpayconfig.getApp_id()); resultMap.put("timeStamp", PayUtil.getCurrentTimeStamp()); resultMap.put("nonceStr", PayUtil.makeUUID(32)); resultMap.put("package", "prepay_id="+resMap.get("prepay_id")); resultMap.put("signType", "MD5"); resultMap.put("sign", PayUtil.createSign(resultMap,wxchatpayconfig.secret)); resultMap.put("returnCode", "SUCCESS"); resultMap.put("returnMsg", "OK"); // System.out.println("【小程序支付】统一下单成功,返回参数:"+resultMap); }else{ resultMap.put("returnCode", resMap.get("return_code")); resultMap.put("returnMsg", resMap.get("return_msg")); System.out.println("【小程序支付】统一下单失败,失败原因:"+resMap.get("return_msg")); } return resultMap; }