|
|
|
@@ -7,10 +7,12 @@ import java.util.Map; |
|
|
|
|
|
|
|
import com.iformall.domain.po.*; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.github.binarywang.wxpay.service.WxPayService; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.Result; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
@@ -23,14 +25,18 @@ import com.iformall.exception.MallinkException; |
|
|
|
import com.iformall.pay.WxPay; |
|
|
|
import com.iformall.pay.WxPayOrderP; |
|
|
|
import com.iformall.pay.WxPayOrderSP; |
|
|
|
import com.iformall.pay.WxPayV3; |
|
|
|
import com.iformall.pay.WxPayment; |
|
|
|
import com.iformall.service.order.entity.WxComposeOrder; |
|
|
|
import com.iformall.service.pay.entity.PayExtraParam; |
|
|
|
import com.iformall.service.pay.service.cashout.wx.v3.entity.CombinePayCommonMiniAppReq; |
|
|
|
import com.iformall.service.pay.service.cashout.wx.v3.entity.PayCommonMiniAppReq; |
|
|
|
import com.iformall.service.pay.service.pay.CDrivingPayService; |
|
|
|
import com.iformall.service.pay.service.pay.entity.PayAdapterResult; |
|
|
|
import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; |
|
|
|
import com.iformall.service.pay.service.pay.wx.v2.BaseWxPayAdapterService; |
|
|
|
import com.iformall.utils.BeanUtils; |
|
|
|
import com.iformall.utils.MaUtil; |
|
|
|
import com.iformall.utils.MapUtil; |
|
|
|
import com.iformall.utils.Utility; |
|
|
|
|
|
|
|
@@ -40,10 +46,14 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
@Service |
|
|
|
public class WxMiniAppPayV3AdapterService implements CDrivingPayService{ |
|
|
|
|
|
|
|
@Autowired |
|
|
|
MaUtil maUtil; |
|
|
|
|
|
|
|
private WxPayOrderP generateWxPayOrderP(WxPayAccount payAccount,WxComposeOrder composeOrder,String productName, WxPayOrder record,String openId,String appId,Date currentDate) throws Exception { |
|
|
|
// 统一下单 普通商户模式 |
|
|
|
String noncestr = Utility.generate32UUID(); |
|
|
|
private PayCommonMiniAppReq generatePayCommonRequest(WxPayAccount payAccount,WxComposeOrder composeOrder,String productName, WxPayOrder record,String openId,String appId,Date currentDate) throws Exception { |
|
|
|
PayCommonMiniAppReq req = new PayCommonMiniAppReq(); |
|
|
|
req.setSp_appid(appId); |
|
|
|
req.set |
|
|
|
String noncestr = Utility.generate32UUID(); |
|
|
|
WxPayOrderP wxPayOrderP = new WxPayOrderP(); |
|
|
|
wxPayOrderP.setOpenid(openId); |
|
|
|
wxPayOrderP.setAppid(appId); |
|
|
|
@@ -66,48 +76,7 @@ public class WxMiniAppPayV3AdapterService implements CDrivingPayService{ |
|
|
|
return wxPayOrderP; |
|
|
|
} |
|
|
|
|
|
|
|
private PayAdapterResult getOrderPResult(Map<String, String> returnMap,WxPayOrder record,WxPayAccount payAccount,String noncestr) { |
|
|
|
PayAdapterResult par = new PayAdapterResult(); |
|
|
|
returnMap.put("payOrderId", String.valueOf(record.getId())); |
|
|
|
String result_code = returnMap.get("result_code"); |
|
|
|
if ("SUCCESS".equals(result_code)) { |
|
|
|
par.setSuccess(true); |
|
|
|
par.setMsg("success."); |
|
|
|
par.setData(returnMap); |
|
|
|
String prepay_id = returnMap.get("prepay_id"); |
|
|
|
// update payOrder with prepay_id |
|
|
|
record.setPrepayId(prepay_id); |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
record.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); |
|
|
|
|
|
|
|
String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); |
|
|
|
Map<String, String> sighMap = MapUtil.getOrderMap(); |
|
|
|
sighMap.put("appId", returnMap.get("appid")); |
|
|
|
sighMap.put("timeStamp", timestamp); |
|
|
|
sighMap.put("nonceStr", noncestr); |
|
|
|
sighMap.put("package", "prepay_id=" + prepay_id); |
|
|
|
sighMap.put("signType", "MD5"); |
|
|
|
String signAgent = WxPayment.createSign(sighMap, payAccount.getApiKey()); |
|
|
|
returnMap.put("timeStamp", timestamp); |
|
|
|
returnMap.put("nonceStr", noncestr); |
|
|
|
returnMap.put("package", "prepay_id=" + prepay_id); |
|
|
|
returnMap.put("paySign", signAgent); |
|
|
|
log.info("back to UI: " + returnMap.toString()); |
|
|
|
} else { |
|
|
|
String errMsg = ""; |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
|
|
|
|
par.setSuccess(false); |
|
|
|
par.setMsg(errMsg); |
|
|
|
par.setData(returnMap); |
|
|
|
} |
|
|
|
|
|
|
|
return par; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private WxPayOrderSP generateWxPayOrderSP(WxPayAccount payAccount, WxComposeOrder composeOrder,String productName,WxPayOrder record,WxAppinfo appInfo,String openId,String appId,Date currentDate,EnumPayShare isShare) throws Exception { |
|
|
|
private CombinePayCommonMiniAppReq generateCombinePayReqeust(WxPayAccount payAccount, WxComposeOrder composeOrder,String productName,WxPayOrder record,WxAppinfo appInfo,String openId,String appId,Date currentDate,EnumPayShare isShare) throws Exception { |
|
|
|
String noncestr = Utility.generate32UUID(); |
|
|
|
WxPayOrderSP wxPayOrderSP = new WxPayOrderSP(); |
|
|
|
wxPayOrderSP.setSub_openid(openId); |
|
|
|
@@ -138,41 +107,22 @@ public class WxMiniAppPayV3AdapterService implements CDrivingPayService{ |
|
|
|
return wxPayOrderSP; |
|
|
|
} |
|
|
|
|
|
|
|
private PayAdapterResult getOrderSPResult(Map<String, String> returnMap,WxPayOrder record,WxPayAccount payAccount,WxAppinfo appInfo,String noncestr) { |
|
|
|
private PayAdapterResult getOrderPResult(String response) { |
|
|
|
PayAdapterResult par = new PayAdapterResult(); |
|
|
|
returnMap.put("payOrderId", String.valueOf(record.getId())); |
|
|
|
String result_code = returnMap.get("result_code"); |
|
|
|
if ("SUCCESS".equals(result_code)) { |
|
|
|
par.setSuccess(true); |
|
|
|
par.setMsg("success."); |
|
|
|
par.setData(returnMap); |
|
|
|
|
|
|
|
String prepay_id = returnMap.get("prepay_id"); |
|
|
|
// update payOrder with prepay_id |
|
|
|
record.setPrepayId(prepay_id); |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
|
|
|
|
String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); |
|
|
|
Map<String, String> sighMap = MapUtil.getOrderMap(); |
|
|
|
sighMap.put("appId", appInfo.getAppId()); |
|
|
|
sighMap.put("timeStamp", timestamp); |
|
|
|
sighMap.put("nonceStr", noncestr); |
|
|
|
sighMap.put("package", "prepay_id=" + prepay_id); |
|
|
|
sighMap.put("signType", "HMAC-SHA256"); |
|
|
|
String signAgent = WxPayment.createSignHMAC(sighMap, payAccount.getApiKey()); |
|
|
|
returnMap.put("timeStamp", timestamp); |
|
|
|
returnMap.put("nonceStr", noncestr); |
|
|
|
returnMap.put("package", "prepay_id=" + prepay_id); |
|
|
|
returnMap.put("paySign", signAgent); |
|
|
|
returnMap.put("signType", "HMAC-SHA256"); |
|
|
|
log.info("back to UI: " + returnMap.toString()); |
|
|
|
} else { |
|
|
|
String errMsg = ""; |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
par.setSuccess(false); |
|
|
|
par.setMsg(errMsg); |
|
|
|
par.setData(returnMap); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(response)) { |
|
|
|
par.setSuccess(false); |
|
|
|
par.setMsg("pay v3 has no response."); |
|
|
|
}else { |
|
|
|
JSONObject result = JSON.parseObject(response); |
|
|
|
String prepayId = result.getString("prepay_id"); |
|
|
|
if (StringUtils.isBlank(prepayId)) { |
|
|
|
par.setSuccess(false); |
|
|
|
par.setMsg("pay v3 has no response."); |
|
|
|
}else { |
|
|
|
par.setSuccess(true); |
|
|
|
par.setMsg("success."); |
|
|
|
} |
|
|
|
} |
|
|
|
return par; |
|
|
|
} |
|
|
|
|
|
|
|
@@ -193,24 +143,24 @@ public class WxMiniAppPayV3AdapterService implements CDrivingPayService{ |
|
|
|
if (payAccount.getType() == EnumPayMode.MCH.getCode()) { |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"当前商户号非服务商模式,不能使用该产品."); |
|
|
|
} |
|
|
|
|
|
|
|
WxPayService payService = maUtil.getWxPayService(appInfo, payAccount); |
|
|
|
|
|
|
|
/* |
|
|
|
* 普通支付/小程序支付 |
|
|
|
* https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_3.shtml |
|
|
|
*/ |
|
|
|
if (!EnumComposeOrder.isMulityMerchantPay(composeOrder.getComposeOrderType())) { |
|
|
|
WxPayOrderP wxPayOrderP = generateWxPayOrderP(payAccount,composeOrder,productName,record,openId,appInfo.getAppId(),currentDate); |
|
|
|
String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderP)); |
|
|
|
log.info("pay order, wechat pushOrder, " + wxPayOrderP.toString() + ", response: " + response.toString()); |
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
return getOrderPResult(returnMap,record,payAccount,wxPayOrderP.getNonce_str()); |
|
|
|
|
|
|
|
PayCommonMiniAppReq payReq = generatePayCommonRequest(payAccount,composeOrder,productName,record,openId,appInfo.getAppId(),currentDate); |
|
|
|
String response = WxPayV3.payCommonWithMiniApp(payService, payReq); |
|
|
|
log.info("pay order v3, " + payReq.toString() + ", response: " + response.toString()); |
|
|
|
return getOrderPResult(response); |
|
|
|
} else { |
|
|
|
//合单支付/小程序支付 |
|
|
|
WxPayOrderSP wxPayOrderSP = generateWxPayOrderSP(payAccount,composeOrder,productName,record,appInfo,openId,appInfo.getAppId(),currentDate,isShare); |
|
|
|
String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderSP)); |
|
|
|
log.info("pay order, wechat pushOrder, " + wxPayOrderSP.toString() + ", response: " + response.toString()); |
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
return getOrderSPResult(returnMap,record,payAccount,appInfo,wxPayOrderSP.getNonce_str()); |
|
|
|
CombinePayCommonMiniAppReq payReq = generateCombinePayReqeust(payAccount,composeOrder,productName,record,appInfo,openId,appInfo.getAppId(),currentDate,isShare); |
|
|
|
String response = WxPayV3.payCombineCommonWithMiniApp(payService, payReq); |
|
|
|
log.info("pay order v3," + payReq.toString() + ", response: " + response.toString()); |
|
|
|
return getOrderPResult(response); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|