|
@@ -132,6 +132,58 @@ public class PayController {
|
|
|
return R.ok(JSONUtil.toJsonStr(response));
|
|
|
}
|
|
|
|
|
|
+ //服务商模式下单
|
|
|
+ public R<String> getPay1(String setOutTradeNo, BigDecimal amount, String openId, String description) throws Exception {
|
|
|
+ String timeExpire = DateTimeZoneUtil.dateToTimeZone(System.currentTimeMillis() + 1000 * 60 * 3);
|
|
|
+ UnifiedOrderModel unifiedOrderModel = new UnifiedOrderModel()
|
|
|
+ .setSp_appid(wxPayProperties.getAppId())
|
|
|
+ .setSp_mchid(wxPayProperties.getMchId())
|
|
|
+ .setSub_mchid("123")//子商户号
|
|
|
+ //商品描述
|
|
|
+ .setDescription(description)
|
|
|
+ //订单号
|
|
|
+ .setOut_trade_no(setOutTradeNo)
|
|
|
+ //交易结束时间
|
|
|
+ .setTime_expire(timeExpire)
|
|
|
+ //附加数据
|
|
|
+ .setAttach("夜来香")
|
|
|
+ //通知地址异步接收微信支付结果通知的回调地址,通知url必须为外网可访问的url,不能携带参数。 公网域名必须为https,如果是走专线接入,使用专线NAT IP或者私有回调域名可使用http
|
|
|
+ //示例值:https://www.weixin.qq.com/wxpay/pay.php
|
|
|
+ .setNotify_url(wxPayProperties.getNotifyUrl())
|
|
|
+ //分账标识
|
|
|
+ .setSettle_info(new SettleInfo().setProfit_sharing(true))
|
|
|
+ //支付金额以分为单位
|
|
|
+ .setAmount(new Amount().setTotal(amount.multiply(new BigDecimal(100)).intValue()))
|
|
|
+ //交易人
|
|
|
+ .setPayer(new Payer().setSp_openid(openId));
|
|
|
+
|
|
|
+ log.info("统一下单参数 {}", JSONUtil.toJsonStr(unifiedOrderModel));
|
|
|
+ IJPayHttpResponse response = WxPayApi.v3(
|
|
|
+ RequestMethodEnum.POST,
|
|
|
+ WxDomainEnum.CHINA.toString(),
|
|
|
+ BasePayApiEnum.PARTNER_JS_API_PAY.toString(),
|
|
|
+ wxPayProperties.getMchId(),
|
|
|
+ getSerialNumber(),
|
|
|
+ null,
|
|
|
+ wxPayProperties.getCertKeyPath(),
|
|
|
+ JSONUtil.toJsonStr(unifiedOrderModel)
|
|
|
+ );
|
|
|
+
|
|
|
+ log.info("统一下单响应 {}", response);
|
|
|
+ // 根据证书序列号查询对应的证书来验证签名结果
|
|
|
+ boolean verifySignature = WxPayKit.verifySignature(response, wxPayProperties.getPlatFormPath());
|
|
|
+ log.info("verifySignature: {}", verifySignature);
|
|
|
+ if (response.getStatus() == SUCCESS && verifySignature) {
|
|
|
+ String body = response.getBody();
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(body);
|
|
|
+ String prepayId = jsonObject.getStr("prepay_id");
|
|
|
+ Map<String, String> map = WxPayKit.jsApiCreateSign(wxPayProperties.getAppId(), prepayId, wxPayProperties.getCertKeyPath());
|
|
|
+ log.info("唤起支付参数:{}", map);
|
|
|
+ return R.ok(JSONUtil.toJsonStr(map));
|
|
|
+ }
|
|
|
+ return R.ok(JSONUtil.toJsonStr(response));
|
|
|
+ }
|
|
|
+
|
|
|
private String getSerialNumber() {
|
|
|
if (StrUtil.isEmpty(serialNo)) {
|
|
|
// 获取证书序列号
|