|
@@ -12,9 +12,8 @@ import com.wechat.pay.contrib.apache.httpclient.cert.CertificatesManager;
|
|
|
import com.wechat.pay.contrib.apache.httpclient.util.PemUtil;
|
|
|
import com.yami.shop.wx.config.CombinePayUrlEnum;
|
|
|
import com.yami.shop.wx.config.WechatPayServiceConfig;
|
|
|
-import com.yami.shop.wx.po.JsapiPo;
|
|
|
+import com.yami.shop.wx.po.JsapiPayInfoPo;
|
|
|
import com.yami.shop.wx.service.WxProviderService;
|
|
|
-import com.yami.shop.wx.utils.HttpUtils;
|
|
|
import com.yami.shop.wx.utils.OrderUtils;
|
|
|
import com.yami.shop.wx.utils.WechatPayValidator;
|
|
|
import lombok.SneakyThrows;
|
|
@@ -45,13 +44,12 @@ import java.util.concurrent.locks.ReentrantLock;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class WxProviderServiceImpl implements WxProviderService {
|
|
|
-
|
|
|
+
|
|
|
@Autowired
|
|
|
private WechatPayServiceConfig wechatPayServiceConfig;
|
|
|
|
|
|
- public Map<String, Object> subJsapi(JsapiPo po) {
|
|
|
+ public Map<String, Object> subJsapi(JsapiPayInfoPo po) {
|
|
|
System.out.println("微信支付传入参数===========" + po);
|
|
|
- String type = "sub_jsapi";
|
|
|
Map<String, Object> params = new HashMap<>(8);
|
|
|
params.put("sp_appid", wechatPayServiceConfig.getSpAppId());
|
|
|
params.put("sp_mchid", wechatPayServiceConfig.getSpMchId());
|
|
@@ -76,15 +74,13 @@ public class WxProviderServiceImpl implements WxProviderService {
|
|
|
params.put("scene_info", sceneInfoMap);
|
|
|
String paramsStr = JSON.toJSONString(params);
|
|
|
log.info("请求参数 ===> {}" + paramsStr);
|
|
|
- String[] split = type.split("_");
|
|
|
- String newType = split[split.length - 1];
|
|
|
- String url = wechatPayServiceConfig.getBaseUrl().concat(CombinePayUrlEnum.PAY_TRANSACTIONS.getType().concat(newType));
|
|
|
+ String url = wechatPayServiceConfig.getBaseUrl().concat(CombinePayUrlEnum.PAY_TRANSACTIONS.getType().concat("jsapi"));
|
|
|
log.info("请求地址 ===> {}" + url);
|
|
|
String resStr = wechatHttpPost(url, paramsStr);
|
|
|
Map<String, Object> resMap = JSONObject.parseObject(resStr, new TypeReference<Map<String, Object>>() {
|
|
|
});
|
|
|
Map<String, Object> signMap = paySignMsgApplet(resMap);
|
|
|
- resMap.put("type", type);
|
|
|
+ resMap.put("type", "sub_jsapi");
|
|
|
resMap.put("signMap", signMap);
|
|
|
return resMap;
|
|
|
}
|
|
@@ -168,26 +164,6 @@ public class WxProviderServiceImpl implements WxProviderService {
|
|
|
return resMap;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 关闭(取消)订单
|
|
|
- *
|
|
|
- * @param orderNo orderNo
|
|
|
- */
|
|
|
- public void closeOrder(String orderNo) {
|
|
|
- // TODO 用于在客户下单后,不进行支付,取消订单的场景
|
|
|
- log.info("根据订单号取消订单,订单号: {}", orderNo);
|
|
|
- String url = String.format(CombinePayUrlEnum.CLOSE_ORDER_BY_NO.getType(), orderNo);
|
|
|
- url = wechatPayServiceConfig.getBaseUrl().concat(url);
|
|
|
- Map<String, String> params = new HashMap<>(2);
|
|
|
- params.put("sp_mchid", wechatPayServiceConfig.getSpMchId());
|
|
|
- params.put("sub_mchid", wechatPayServiceConfig.getSubAppId());
|
|
|
- String paramsStr = JSON.toJSONString(params);
|
|
|
- log.info("请求参数 ===> {}" + paramsStr);
|
|
|
- String res = wechatHttpPost(url, paramsStr);
|
|
|
- log.info(res);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 申请退款
|
|
|
*
|
|
@@ -195,7 +171,7 @@ public class WxProviderServiceImpl implements WxProviderService {
|
|
|
* @return orderNo
|
|
|
*/
|
|
|
@Override
|
|
|
- public String refundOrder(String orderNo,Integer refundMoney,Integer total) {
|
|
|
+ public String refundOrder(String orderNo, Integer refundMoney, Integer total) {
|
|
|
log.info("根据订单号申请退款,订单号: {}", orderNo);
|
|
|
String url = wechatPayServiceConfig.getBaseUrl().concat(CombinePayUrlEnum.DOMESTIC_REFUNDS.getType());
|
|
|
Map<String, Object> params = new HashMap<>(2);
|
|
@@ -412,7 +388,7 @@ public class WxProviderServiceImpl implements WxProviderService {
|
|
|
}
|
|
|
|
|
|
private JSONObject getNotifyBodyJson(HttpServletRequest request) {
|
|
|
- String body = HttpUtils.readData(request);
|
|
|
+ String body = WechatPayValidator.readData(request);
|
|
|
log.info("===========微信回调参数===========\n" + body);
|
|
|
log.info("微信回调参数:{}", body);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(body);
|
|
@@ -481,5 +457,4 @@ public class WxProviderServiceImpl implements WxProviderService {
|
|
|
resMap.put("message", "成功");
|
|
|
return resMap;
|
|
|
}
|
|
|
-
|
|
|
}
|