|
|
@ -1,5 +1,6 @@
|
|
|
|
package com.luoo.user.controller;
|
|
|
|
package com.luoo.user.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import api.Result;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.http.ContentType;
|
|
|
|
import cn.hutool.http.ContentType;
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
@ -15,6 +16,7 @@ import com.ijpay.wxpay.enums.WxDomainEnum;
|
|
|
|
import com.ijpay.wxpay.enums.v3.BasePayApiEnum;
|
|
|
|
import com.ijpay.wxpay.enums.v3.BasePayApiEnum;
|
|
|
|
import com.ijpay.wxpay.model.UnifiedOrderModel;
|
|
|
|
import com.ijpay.wxpay.model.UnifiedOrderModel;
|
|
|
|
import com.luoo.user.config.WxPayConfig;
|
|
|
|
import com.luoo.user.config.WxPayConfig;
|
|
|
|
|
|
|
|
import com.luoo.user.util.RedisUtils;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
@ -43,10 +45,13 @@ public class WxPayController {
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private WxPayConfig wxPayConfig;
|
|
|
|
private WxPayConfig wxPayConfig;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private RedisUtils redisUtils;
|
|
|
|
|
|
|
|
|
|
|
|
//支付
|
|
|
|
//支付
|
|
|
|
@RequestMapping("/app")
|
|
|
|
@RequestMapping("/app")
|
|
|
|
@ResponseBody
|
|
|
|
@ResponseBody
|
|
|
|
public String jsApiPay() {
|
|
|
|
public Result<Object> jsApiPay() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String timeExpire = DateTimeZoneUtil.dateToTimeZone(System.currentTimeMillis() + 1000 * 60 * 3);
|
|
|
|
String timeExpire = DateTimeZoneUtil.dateToTimeZone(System.currentTimeMillis() + 1000 * 60 * 3);
|
|
|
|
UnifiedOrderModel unifiedOrderModel = new UnifiedOrderModel()
|
|
|
|
UnifiedOrderModel unifiedOrderModel = new UnifiedOrderModel()
|
|
|
@ -66,11 +71,12 @@ public class WxPayController {
|
|
|
|
params.put("time_expire", timeExpire);
|
|
|
|
params.put("time_expire", timeExpire);
|
|
|
|
params.put("notify_url", "https://www.baidu.com");
|
|
|
|
params.put("notify_url", "https://www.baidu.com");
|
|
|
|
params.put("amount", new HashMap<String, Object>() {{
|
|
|
|
params.put("amount", new HashMap<String, Object>() {{
|
|
|
|
put("total", 1);
|
|
|
|
put("total", 0.01);
|
|
|
|
put("currency", "CNY");
|
|
|
|
put("currency", "CNY");
|
|
|
|
}});
|
|
|
|
}});
|
|
|
|
|
|
|
|
|
|
|
|
log.info("统一下单参数 {}", JSONUtil.toJsonStr(params));
|
|
|
|
log.info("统一下单参数 {}", JSONUtil.toJsonStr(params));
|
|
|
|
|
|
|
|
redisUtils.set(params.get("out_trade_no").toString(), params);
|
|
|
|
IJPayHttpResponse response = WxPayApi.v3(
|
|
|
|
IJPayHttpResponse response = WxPayApi.v3(
|
|
|
|
RequestMethodEnum.POST,
|
|
|
|
RequestMethodEnum.POST,
|
|
|
|
WxDomainEnum.CHINA.toString(),
|
|
|
|
WxDomainEnum.CHINA.toString(),
|
|
|
@ -90,14 +96,15 @@ public class WxPayController {
|
|
|
|
String body = response.getBody();
|
|
|
|
String body = response.getBody();
|
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(body);
|
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(body);
|
|
|
|
String prepayId = jsonObject.getStr("prepay_id");
|
|
|
|
String prepayId = jsonObject.getStr("prepay_id");
|
|
|
|
Map<String, String> map = WxPayKit.jsApiCreateSign(wxPayConfig.getAppId(), prepayId, wxPayConfig.getPrivateKeyPath());
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> map = WxPayKit.appCreateSign(wxPayConfig.getAppId(), wxPayConfig.getMchId(), prepayId, wxPayConfig.getPrivateKeyPath());
|
|
|
|
log.info("唤起支付参数:{}", map);
|
|
|
|
log.info("唤起支付参数:{}", map);
|
|
|
|
return JSONUtil.toJsonStr(map);
|
|
|
|
return Result.success(map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return JSONUtil.toJsonStr(response);
|
|
|
|
return Result.success(response);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
return e.getMessage();
|
|
|
|
return Result.failed(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -120,6 +127,7 @@ public class WxPayController {
|
|
|
|
wxPayConfig.getApiV3Key(), wxPayConfig.getPlatformCertPath());
|
|
|
|
wxPayConfig.getApiV3Key(), wxPayConfig.getPlatformCertPath());
|
|
|
|
|
|
|
|
|
|
|
|
log.info("支付通知明文 {}", plainText);
|
|
|
|
log.info("支付通知明文 {}", plainText);
|
|
|
|
|
|
|
|
redisUtils.set("payNotify" + DateTimeZoneUtil.dateToTimeZone(System.currentTimeMillis()), plainText);
|
|
|
|
|
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(plainText)) {
|
|
|
|
if (StrUtil.isNotEmpty(plainText)) {
|
|
|
|
response.setStatus(200);
|
|
|
|
response.setStatus(200);
|
|
|
@ -139,5 +147,4 @@ public class WxPayController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|