package com.java110.acct.cmd.payment;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.java110.acct.payment.IPaymentBusiness;
|
import com.java110.core.annotation.Java110Cmd;
|
import com.java110.core.context.CmdContextUtils;
|
import com.java110.core.context.ICmdDataFlowContext;
|
import com.java110.core.event.cmd.Cmd;
|
import com.java110.core.event.cmd.CmdEvent;
|
import com.java110.core.factory.CommunitySettingFactory;
|
import com.java110.core.factory.GenerateCodeFactory;
|
import com.java110.core.factory.WechatFactory;
|
import com.java110.core.log.LoggerFactory;
|
import com.java110.dto.payment.*;
|
import com.java110.dto.wechat.SmallWeChatDto;
|
import com.java110.intf.acct.IPaymentKeyV1InnerServiceSMO;
|
import com.java110.intf.acct.IPaymentPoolConfigV1InnerServiceSMO;
|
import com.java110.intf.acct.IPaymentPoolV1InnerServiceSMO;
|
import com.java110.intf.acct.IPaymentPoolValueV1InnerServiceSMO;
|
import com.java110.intf.fee.IPayFeeV1InnerServiceSMO;
|
import com.java110.utils.cache.CommonCache;
|
import com.java110.utils.cache.MappingCache;
|
import com.java110.utils.cache.UrlCache;
|
import com.java110.utils.constant.MappingConstant;
|
import com.java110.utils.constant.WechatConstant;
|
import com.java110.utils.exception.CmdException;
|
import com.java110.utils.factory.ApplicationContextFactory;
|
import com.java110.utils.util.Assert;
|
import com.java110.utils.util.DateUtil;
|
import com.java110.utils.util.PayUtil;
|
import com.java110.vo.ResultVo;
|
import org.slf4j.Logger;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.http.*;
|
import org.springframework.web.client.RestTemplate;
|
|
import java.text.ParseException;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
/**
|
* native qrcode 支付
|
* add by wuxw 2023-06-25
|
*/
|
@Java110Cmd(serviceCode = "payment.nativeQrcodePayment")
|
public class NativeQrcodePaymentCmd extends Cmd {
|
|
|
private static final Logger logger = LoggerFactory.getLogger(NativeQrcodePaymentCmd.class);
|
|
protected static final String DEFAULT_PAYMENT_ADAPT = "wechatNativeQrcodePaymentFactory";// 默认微信通用支付
|
|
@Autowired
|
private IPaymentKeyV1InnerServiceSMO paymentKeyV1InnerServiceSMOImpl;
|
|
@Autowired
|
private IPaymentPoolValueV1InnerServiceSMO paymentPoolValueV1InnerServiceSMOImpl;
|
|
@Autowired
|
private IPaymentPoolConfigV1InnerServiceSMO paymentPoolConfigV1InnerServiceSMOImpl;
|
|
@Autowired
|
private IPaymentPoolV1InnerServiceSMO paymentPoolV1InnerServiceSMOImpl;
|
|
@Autowired
|
private IPayFeeV1InnerServiceSMO payFeeV1InnerServiceSMOImpl;
|
|
@Override
|
public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
|
Assert.hasKeyAndValue(reqJson, "business", "未包含业务");
|
Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区");
|
|
}
|
|
|
|
private static final String VERSION = "1.0";
|
@Value("${fuiou.pay.unified-order-url}")
|
public String PAY_UNIFIED_ORDER_URL;
|
@Autowired
|
private RestTemplate outRestTemplate;
|
@Override
|
public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
|
// if (!(reqJson.containsKey("communityId"))){
|
// reqJson.put("communityId","2025062600070012");
|
// }
|
PaymentPoolDto paymentPoolDto = new PaymentPoolDto();
|
paymentPoolDto.setCommunityId(reqJson.getString("communityId"));
|
paymentPoolDto.setPage(1);
|
paymentPoolDto.setRow(10);
|
List<PaymentPoolDto> paymentPoolDtos = paymentPoolV1InnerServiceSMOImpl.queryPaymentPools(paymentPoolDto);
|
List<PaymentPoolDto> collect = paymentPoolDtos.stream().filter(e -> e.getPaymentType().equals("FUIOU")).collect(Collectors.toList());
|
PaymentPoolValueDto paymentPoolValueDto = new PaymentPoolValueDto();
|
paymentPoolValueDto.setPpId(collect.get(0).getPpId());
|
paymentPoolValueDto.setCommunityId(reqJson.getString("communityId"));
|
List<PaymentPoolValueDto> values = paymentPoolValueV1InnerServiceSMOImpl.queryPaymentPoolValues(paymentPoolValueDto);
|
Map<String, List<PaymentPoolValueDto>> payMap = values.stream().collect(Collectors.groupingBy(PaymentPoolValueDto::getColumnKey));
|
SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
|
if(payMap.containsKey("FUIOU_APP_ID")){
|
smallWeChatDto.setAppId(payMap.get("FUIOU_APP_ID").get(0).getColumnValue());
|
}else{
|
smallWeChatDto.setAppId(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appId"));
|
}
|
if(payMap.containsKey("FUIOU_MCHNT_KEY")){
|
smallWeChatDto.setAppSecret(payMap.get("FUIOU_MCHNT_KEY").get(0).getColumnValue());
|
}else{
|
smallWeChatDto.setAppSecret(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appSecret"));
|
}
|
if(payMap.containsKey("FUIOU_ORDER_PRE")){
|
smallWeChatDto.setOrderPre(payMap.get("FUIOU_ORDER_PRE").get(0).getColumnValue());
|
}
|
if(payMap.containsKey("FUIOU_MERCHANT_ID")){
|
smallWeChatDto.setMchId(payMap.get("FUIOU_MERCHANT_ID").get(0).getColumnValue());
|
}else{
|
smallWeChatDto.setMchId(MappingCache.getValue(MappingConstant.WECHAT_STORE_DOMAIN, "mchId"));
|
}
|
logger.debug(">>>>>>>>>>>>>>>>支付参数报文,{}", reqJson.toJSONString());
|
String appId = context.getReqHeaders().get("app-id");
|
String userId = context.getReqHeaders().get("user-id");
|
reqJson.put("createUserId", userId);
|
reqJson.put("storeId", CmdContextUtils.getStoreId(context));
|
|
//1.0 查询当前支付的业务
|
|
IPaymentBusiness paymentBusiness = ApplicationContextFactory.getBean(reqJson.getString("business"), IPaymentBusiness.class);
|
|
if (paymentBusiness == null) {
|
throw new CmdException("当前支付业务不支持");
|
}
|
|
//2.0 相应业务 下单 返回 单号 ,金额,
|
PaymentOrderDto paymentOrderDto = paymentBusiness.unified(context, reqJson);
|
paymentOrderDto.setAppId(appId);
|
paymentOrderDto.setUserId(userId);
|
reqJson.put("money", paymentOrderDto.getMoney());
|
|
String token = GenerateCodeFactory.getUUID();
|
|
// redis 中 保存 请求参数
|
CommonCache.setValue("nativeQrcodePayment_" + token, reqJson.toJSONString(), CommonCache.PAY_DEFAULT_EXPIRE_TIME);
|
JSONObject result = new JSONObject();
|
|
String notifyUrl = UrlCache.getOwnerUrl() + "/app/payment/notify/wechat/"+appId+"/"+reqJson.getString("paymentPoolId");
|
|
//
|
//
|
// List<PaymentKeyDto> paymentKeyDtos = null;
|
//
|
// PaymentKeyDto paymentKeyDto = new PaymentKeyDto();
|
// paymentKeyDto.setPaymentType("FUIOU");
|
// paymentKeyDtos = paymentKeyV1InnerServiceSMOImpl.queryPaymentKeys(paymentKeyDto);
|
//
|
|
String systemName = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, WechatConstant.PAY_GOOD_NAME);
|
JSONObject paramMap = new JSONObject();
|
paramMap.put("version", VERSION);
|
paramMap.put("mchnt_cd", smallWeChatDto.getMchId()); // 富友分配给二级商户的商户号
|
paramMap.put("random_str", PayUtil.makeUUID(32));
|
paramMap.put("order_amt", (int)(paymentOrderDto.getMoney()*100));
|
String generatorId = GenerateCodeFactory.getGeneratorId("81");
|
paramMap.put("mchnt_order_no", smallWeChatDto.getOrderPre() + generatorId);
|
paramMap.put("txn_begin_ts", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_DEFAULT));
|
paramMap.put("goods_des", systemName + "测试");
|
paramMap.put("term_id", "abcdefgh");
|
paramMap.put("term_ip", PayUtil.getLocalIp());
|
paramMap.put("notify_url", notifyUrl + "?wId=" + WechatFactory.getWId(smallWeChatDto.getAppId()));
|
paramMap.put("trade_type", "WXBXLET");
|
paramMap.put("order_type", "WECHAT");
|
// paramMap.put("sub_openid", openid);
|
// paramMap.put("sub_appid", smallWeChatDto.getAppId());
|
|
paramMap.put("sign", createSign(paramMap, smallWeChatDto.getAppSecret()));
|
|
logger.debug("调用支付统一下单接口" + paramMap.toJSONString());
|
HttpHeaders headers = new HttpHeaders();
|
headers.add("Content-Type", "application/json");
|
HttpEntity httpEntity = new HttpEntity(paramMap.toJSONString(), headers);
|
ResponseEntity<String> responseEntity = outRestTemplate.exchange(PAY_UNIFIED_ORDER_URL
|
, HttpMethod.POST, httpEntity, String.class);
|
if(JSONObject.parseObject(responseEntity.getBody()).get("result_msg").equals("SUCCESS")){
|
result.put("codeUrl", JSONObject.parseObject(responseEntity.getBody()).get("qr_code"));
|
ResponseEntity<String> responseEntity2 = ResultVo.createResponseEntity(result);
|
logger.debug("调用支付厂家返回,{}", responseEntity2);
|
context.setResponseEntity(responseEntity2);
|
}else{
|
result.put("codeUrl", JSONObject.parseObject(responseEntity.getBody()).get("qr_code"));
|
ResponseEntity<String> responseEntity2 = ResultVo.createResponseEntity(responseEntity);
|
logger.debug("调用支付厂家返回,{}", responseEntity);
|
context.setResponseEntity(responseEntity2);
|
}
|
|
}
|
private String createSign(JSONObject paramMap, String payPassword) {
|
String str = paramMap.getString("mchnt_cd") + "|"
|
+ paramMap.getString("order_type") + "|"
|
+ paramMap.getString("order_amt") + "|"
|
+ paramMap.getString("mchnt_order_no") + "|"
|
+ paramMap.getString("txn_begin_ts") + "|"
|
+ paramMap.getString("goods_des") + "|"
|
+ paramMap.getString("term_id") + "|"
|
+ paramMap.getString("term_ip") + "|"
|
+ paramMap.getString("notify_url") + "|"
|
+ paramMap.getString("random_str") + "|"
|
+ paramMap.getString("version") + "|"
|
+ payPassword;
|
return PayUtil.md5(str);
|
}
|
|
}
|