|
|
@@ -1,198 +0,0 @@ |
|
|
|
package com.iformall.service.wx; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.Result; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.po.PosCouponOrderVerify; |
|
|
|
import com.iformall.domain.po.WxAppinfo; |
|
|
|
import com.iformall.domain.po.WxBatchOrder; |
|
|
|
import com.iformall.domain.po.WxCouponOrder; |
|
|
|
import com.iformall.domain.po.WxOrder; |
|
|
|
import com.iformall.domain.po.WxPayAccount; |
|
|
|
import com.iformall.domain.po.WxPayOrder; |
|
|
|
import com.iformall.enums.EnumCouponOrderStatus; |
|
|
|
import com.iformall.enums.EnumOrderFrom; |
|
|
|
import com.iformall.enums.EnumOrderStatus; |
|
|
|
import com.iformall.enums.EnumOrderType; |
|
|
|
import com.iformall.enums.EnumPayMode; |
|
|
|
import com.iformall.enums.EnumPayStatus; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
import com.iformall.pay.WxPay; |
|
|
|
import com.iformall.pay.WxPayOrderQ; |
|
|
|
import com.iformall.pay.WxPayOrderSQ; |
|
|
|
import com.iformall.pay.WxPayment; |
|
|
|
import com.iformall.service.QrCodeService; |
|
|
|
import com.iformall.service.helper.WxPayOrderServiceHelper; |
|
|
|
import com.iformall.service.order.entity.WxComposeChildOrderShare; |
|
|
|
import com.iformall.service.pay.service.pay.PayAdapterService; |
|
|
|
import com.iformall.service.pay.service.pay.entity.PayAdapterResult; |
|
|
|
import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; |
|
|
|
import com.iformall.utils.BeanUtils; |
|
|
|
import com.iformall.utils.MaUtil; |
|
|
|
import com.iformall.utils.MapUtil; |
|
|
|
import com.iformall.utils.QRCodeUtils; |
|
|
|
import com.iformall.utils.Utility; |
|
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService; |
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import me.chanjar.weixin.common.error.WxErrorException; |
|
|
|
import me.chanjar.weixin.open.api.WxOpenService; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
public class BaseWxPayAdapterService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxOpenService openService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
MaUtil maUtil; |
|
|
|
|
|
|
|
/** |
|
|
|
* 做为支付的扩展数据 |
|
|
|
* @param payOrder |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
protected String getAttach(WxPayOrder payOrder) { |
|
|
|
Map<String,String> map = new HashMap<>(); |
|
|
|
map.put("tenantId",payOrder.getTenantId()); |
|
|
|
return JSON.toJSONString(map); |
|
|
|
} |
|
|
|
|
|
|
|
protected String getMerchantUid(WxPayOrder payOrder,WxOrder order) { |
|
|
|
WxComposeChildOrderShare share = payOrder.getChildOrderShare(order.getId()); |
|
|
|
return share.getMerchantUid(); |
|
|
|
} |
|
|
|
|
|
|
|
protected File getQrCode(WxAppinfo appinfo,String pageUrl,int type,String sceneParam) throws WxErrorException { |
|
|
|
boolean isFmOpen = false; |
|
|
|
WxMaService wxMaService; |
|
|
|
if(isFmOpen) { |
|
|
|
wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appinfo.getAppId()); |
|
|
|
} else { |
|
|
|
wxMaService = maUtil.getWeappService(appinfo); |
|
|
|
} |
|
|
|
|
|
|
|
boolean autoColor = false; |
|
|
|
boolean isHyaline = true; |
|
|
|
WxMaCodeLineColor color = new WxMaCodeLineColor("0", "0", "0"); |
|
|
|
|
|
|
|
String pathStr = ""; |
|
|
|
if (StringUtils.isNotBlank(sceneParam)) { |
|
|
|
pathStr = pageUrl + "?scene="+sceneParam; |
|
|
|
} else { |
|
|
|
pathStr = pageUrl; |
|
|
|
} |
|
|
|
if(type == 0) { |
|
|
|
final File codeFile = wxMaService.getQrcodeService().createQrcode(pathStr, QRCodeUtils.QR_WIDTH); |
|
|
|
return codeFile; |
|
|
|
}else { |
|
|
|
final File codeFile = wxMaService.getQrcodeService().createWxaCodeUnlimit(sceneParam, pageUrl, QRCodeUtils.QR_WIDTH, autoColor, color, isHyaline); |
|
|
|
return codeFile; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
JSONObject errorMapClose = JSON.parseObject("{" + |
|
|
|
"\"ORDERPAID\":{\"detail\":\"订单已支付\",\"reason\":\"订单已支付,不能发起关单\",\"resolution\":\"订单已支付,不能发起关单,请当作已支付的正常交易\"}," + |
|
|
|
"\"SYSTEMERROR\":{\"detail\":\"系统错误\",\"reason\":\"系统错误\",\"resolution\":\"系统异常,请重新调用该API\"}," + |
|
|
|
"\"ORDERCLOSED\":{\"detail\":\"订单已关闭\",\"reason\":\"订单已关闭,无法重复关闭\",\"resolution\":\"订单已关闭,无需继续调用\"}," + |
|
|
|
"\"SIGNERROR\":{\"detail\":\"签名错误\",\"reason\":\"参数签名结果不正确\",\"resolution\":\"请检查签名参数和方法是否都符合签名算法要求\"}," + |
|
|
|
"\"REQUIRE_POST_METHOD\":{\"detail\":\"请使用post方法\",\"reason\":\"未使用post传递参数\",\"resolution\":\"请检查请求参数是否通过post方法提交\"}," + |
|
|
|
"\"XML_FORMAT_ERROR\":{\"detail\":\"XML格式错误\t\",\"reason\":\"XML格式错误\",\"reason\":\"请检查XML参数格式是否正确\"}}"); |
|
|
|
|
|
|
|
/** |
|
|
|
* 收款码支付回撤,都是2.0版本 |
|
|
|
* @param appInfo |
|
|
|
* @param record |
|
|
|
* @param payAccount |
|
|
|
* @return |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
|
|
|
|
protected PayAdapterResult payOrderReverse(WxAppinfo appInfo, WxPayOrder record,WxPayAccount payAccount,String subMchId) throws Exception { |
|
|
|
String response = payOrderReverseWx(appInfo, record,payAccount,subMchId); |
|
|
|
log.info("pay order reverse, " + record.toString() + ", response: " + response); |
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
String return_code = returnMap.get("return_code"); |
|
|
|
String result_code = returnMap.get("result_code"); |
|
|
|
if ("SUCCESS".equalsIgnoreCase(return_code)) { |
|
|
|
if ("SUCCESS".equals(result_code)) { |
|
|
|
return new PayAdapterResult(true, "订单撤销成功", returnMap, null); |
|
|
|
} else { |
|
|
|
String errMsg = ""; |
|
|
|
JSONObject errObj = errorMapClose.getJSONObject(result_code); |
|
|
|
if (errObj != null) { |
|
|
|
errMsg = errObj.toJSONString(); |
|
|
|
} else { |
|
|
|
errMsg = returnMap.get("return_msg"); |
|
|
|
} |
|
|
|
return new PayAdapterResult(false, errMsg, returnMap, null); |
|
|
|
} |
|
|
|
} else { |
|
|
|
String errMsg = returnMap.get("return_msg"); |
|
|
|
return new PayAdapterResult(false, errMsg, returnMap, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private String payOrderReverseWx(WxAppinfo appInfo, WxPayOrder record,WxPayAccount payAccount,String subMchId) { |
|
|
|
// get payAccount |
|
|
|
if (payAccount.getType() == EnumPayMode.MCH.getCode()) { |
|
|
|
// 普通商户号模式 |
|
|
|
WxPayOrderQ payOrderC = new WxPayOrderQ(); |
|
|
|
String noncestr = Utility.generate32UUID(); |
|
|
|
payOrderC.setAppid(appInfo.getAppId()); |
|
|
|
payOrderC.setMch_id(payAccount.getMchId()); |
|
|
|
payOrderC.setNonce_str(noncestr); |
|
|
|
payOrderC.setOut_trade_no(record.getPayOrderNo()); |
|
|
|
|
|
|
|
try { |
|
|
|
Map map = BeanUtils.toStringMap(payOrderC); |
|
|
|
payOrderC.setSign(WxPayment.createSign(map, payAccount.getApiKey())); |
|
|
|
map = BeanUtils.toStringMap(payOrderC); |
|
|
|
String response = WxPay.orderReverse(map, payAccount.getCertPath(), payAccount.getMchId()); |
|
|
|
log.info("request:" + map.toString() + "\nresponse:" + response); |
|
|
|
return response; |
|
|
|
} catch (RuntimeException e) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 服务商模式 |
|
|
|
WxPayOrderSQ payOrderSC = new WxPayOrderSQ(); |
|
|
|
String noncestr = Utility.generate32UUID(); |
|
|
|
payOrderSC.setAppid(appInfo.getParentAppId()); |
|
|
|
payOrderSC.setSub_appid(appInfo.getAppId()); |
|
|
|
payOrderSC.setMch_id(payAccount.getMchId()); |
|
|
|
payOrderSC.setSub_mch_id(subMchId); |
|
|
|
payOrderSC.setNonce_str(noncestr); |
|
|
|
payOrderSC.setOut_trade_no(record.getPayOrderNo()); |
|
|
|
payOrderSC.setSign_type("HMAC-SHA256"); |
|
|
|
|
|
|
|
try { |
|
|
|
Map map = BeanUtils.toStringMap(payOrderSC); |
|
|
|
payOrderSC.setSign(WxPayment.createSignHMAC(map, payAccount.getApiKey())); |
|
|
|
map = BeanUtils.toStringMap(payOrderSC); |
|
|
|
String response = WxPay.orderReverse(map, payAccount.getCertPath(), payAccount.getMchId()); |
|
|
|
log.info("request:" + map.toString() + "\nresponse:" + response); |
|
|
|
return response; |
|
|
|
} catch (RuntimeException e) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |