|
|
|
@@ -2,6 +2,7 @@ package com.iformall.service.pay.service.pay.wx.v2.miniApp.appPay; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@@ -58,6 +59,30 @@ public class WxMiniAppPayAdapterService extends BaseWxPayV2AdapterService implem |
|
|
|
"\"POST_DATA_EMPTY\":{\"detail\":\"post数据为空\",\"reason\":\"post数据不能为空\",\"resolution\":\"请检查post数据是否为空\"}," + |
|
|
|
"\"NOT_UTF8\":{\"detail\":\"编码格式错误\",\"reason\":\"未使用指定编码格式\",\"resolution\":\"请使用UTF-8编码格式\"}}"); |
|
|
|
|
|
|
|
private WxPayOrderP generateWxPayOrderP(String openId,String appId,String mchId,String productName,String attach,String payOrderNo,Integer fee,String ip,String notifyUrl,String apiKey,Date currentDate)throws Exception { |
|
|
|
// 统一下单 普通商户模式 |
|
|
|
String noncestr = Utility.generate32UUID(); |
|
|
|
WxPayOrderP wxPayOrderP = new WxPayOrderP(); |
|
|
|
wxPayOrderP.setOpenid(openId); |
|
|
|
wxPayOrderP.setAppid(appId); |
|
|
|
wxPayOrderP.setMch_id(mchId); |
|
|
|
wxPayOrderP.setNonce_str(noncestr); |
|
|
|
wxPayOrderP.setBody(productName); |
|
|
|
wxPayOrderP.setAttach(attach); |
|
|
|
wxPayOrderP.setOut_trade_no(payOrderNo); |
|
|
|
wxPayOrderP.setTotal_fee(fee); |
|
|
|
wxPayOrderP.setSpbill_create_ip(ip); // 终端IP |
|
|
|
wxPayOrderP.setGoods_tag(productName); |
|
|
|
wxPayOrderP.setNotify_url(notifyUrl); |
|
|
|
wxPayOrderP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 |
|
|
|
wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); |
|
|
|
Date futureDate = new Date(); |
|
|
|
futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); |
|
|
|
wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 |
|
|
|
Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderP); |
|
|
|
wxPayOrderP.setSign(WxPayment.createSign(payOrderMap, apiKey)); |
|
|
|
return wxPayOrderP; |
|
|
|
} |
|
|
|
|
|
|
|
private WxPayOrderP generateWxPayOrderP(WxPayAccount payAccount,WxComposeOrder composeOrder,String productName, WxPayOrder record,String openId,String appId,Date currentDate) throws Exception { |
|
|
|
// 统一下单 普通商户模式 |
|
|
|
@@ -132,6 +157,42 @@ public class WxMiniAppPayAdapterService extends BaseWxPayV2AdapterService implem |
|
|
|
return par; |
|
|
|
} |
|
|
|
|
|
|
|
private PayAdapterResult getOrderPResult(Map<String, String> returnMap,String noncestr,String apiKey) { |
|
|
|
PayAdapterResult par = new PayAdapterResult(); |
|
|
|
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"); |
|
|
|
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, apiKey); |
|
|
|
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 = ""; |
|
|
|
JSONObject errObj = errorMap.getJSONObject(result_code); |
|
|
|
if (errObj != null) { |
|
|
|
errMsg = errObj.toJSONString(); |
|
|
|
} else { |
|
|
|
errMsg = returnMap.get("return_msg"); |
|
|
|
} |
|
|
|
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 { |
|
|
|
@@ -247,6 +308,14 @@ public class WxMiniAppPayAdapterService extends BaseWxPayV2AdapterService implem |
|
|
|
return getOrderSPResult(returnMap,record,payAccount,appInfo,wxPayOrderSP.getNonce_str()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public PayAdapterResult pay(String openId,String appId,String mchId,String productName,String attach,String payOrderNo,Integer fee,String ip,String notifyUrl,String apiKey,Date currentDate) throws Exception { |
|
|
|
WxPayOrderP wxPayOrderP = generateWxPayOrderP(openId, appId, mchId, productName, attach, payOrderNo, fee, ip, notifyUrl, apiKey, 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,wxPayOrderP.getNonce_str(),apiKey); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PayQueryAdapterResult queryPayStatus(WxPayOrder oldRecord, WxAppinfo appInfo, |
|
|
|
|