wuxw
2022-10-05 84cacadcd982a2bb4fa43e610a3dc73f54a272b3
优化代码 开发完成协议
3个文件已修改
16个文件已添加
978 ■■■■■ 已修改文件
java110-bean/src/main/java/com/java110/dto/payment/PaymentOrderDto.java 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-interface/src/main/java/com/java110/intf/acct/INotifyPaymentV1InnerServiceSMO.java 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-utils/src/main/java/com/java110/utils/constant/WechatConstant.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-acct/src/main/java/com/java110/acct/cmd/payment/UnifiedPaymentCmd.java 136 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-acct/src/main/java/com/java110/acct/payment/.DS_Store 补丁 | 查看 | 原始文档 | blame | 历史
service-acct/src/main/java/com/java110/acct/payment/IPaymentBusiness.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-acct/src/main/java/com/java110/acct/payment/IPaymentFactoryAdapt.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-acct/src/main/java/com/java110/acct/payment/adapt/package-info.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-acct/src/main/java/com/java110/acct/payment/adapt/wechat/WechatPaymentFactoryAdapt.java 295 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-acct/src/main/java/com/java110/acct/payment/business/.DS_Store 补丁 | 查看 | 原始文档 | blame | 历史
service-acct/src/main/java/com/java110/acct/payment/business/package-info.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-acct/src/main/java/com/java110/acct/payment/business/venue/VenueReservationPaymentBusiness.java 128 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-acct/src/main/java/com/java110/acct/smo/impl/NotifyPaymentV1InnerServiceSMOImpl.java 98 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-api/src/main/java/com/java110/api/configuration/ServiceConfiguration.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-api/src/main/java/com/java110/api/controller/app/payment/NotifyPaymentController.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-api/src/main/java/com/java110/api/controller/app/payment/wechat/WechatNotifyPaymentController.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot/src/main/java/com/java110/boot/configuration/ServiceConfiguration.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot/src/main/java/com/java110/boot/controller/app/payment/NotifyPaymentController.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springboot/src/main/java/com/java110/boot/controller/app/payment/wechat/WechatNotifyPaymentController.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-bean/src/main/java/com/java110/dto/payment/PaymentOrderDto.java
New file
@@ -0,0 +1,56 @@
package com.java110.dto.payment;
import org.springframework.http.ResponseEntity;
import java.io.Serializable;
/**
 * 支付订单信息
 * 封装实体类
 */
public class PaymentOrderDto implements Serializable{
    private String orderId;
    //金额
    private double money;
    private String name;
    private ResponseEntity<String> responseEntity;
    public String getOrderId() {
        return orderId;
    }
    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }
    public double getMoney() {
        return money;
    }
    public void setMoney(double money) {
        this.money = money;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public ResponseEntity<String> getResponseEntity() {
        return responseEntity;
    }
    public void setResponseEntity(ResponseEntity<String> responseEntity) {
        this.responseEntity = responseEntity;
    }
}
java110-interface/src/main/java/com/java110/intf/acct/INotifyPaymentV1InnerServiceSMO.java
New file
@@ -0,0 +1,47 @@
/*
 * Copyright 2017-2020 吴学文 and java110 team.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.java110.intf.acct;
import com.alibaba.fastjson.JSONObject;
import com.java110.config.feign.FeignConfiguration;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
 * 类表述: 服务之前调用的接口类,不对外提供接口能力 只用于接口建调用
 * add by 吴学文 at 2021-12-21 13:05:25 mail: 928255095@qq.com
 * open source address: https://gitee.com/wuxw7/MicroCommunity
 * 官网:http://www.homecommunity.cn
 * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
 * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
 */
@FeignClient(name = "acct-service", configuration = {FeignConfiguration.class})
@RequestMapping("/notifyPaymentV1Api")
public interface INotifyPaymentV1InnerServiceSMO {
    /**
     * 查询<p>小区楼</p>总记录数
     *
     * @param reqJson 数据对象分享
     * @return 小区下的小区楼记录数
     */
    @RequestMapping(value = "/notifyPayment", method = RequestMethod.POST)
    public ResponseEntity<String> notifyPayment(@RequestBody String reqJson);
}
java110-utils/src/main/java/com/java110/utils/constant/WechatConstant.java
@@ -60,9 +60,12 @@
    //支付适配器
    public static final String PAY_ADAPT = "PAY_ADAPT";
    public static final String PAYMENT_ADAPT = "PAYMENT_ADAPT";
    public static final String PAY_QR_ADAPT = "PAY_QR_ADAPT";
    //支付通知适配器
    public static final String PAY_NOTIFY_ADAPT = "PAY_NOTIFY_ADAPT";
    public static final String PAYMENT_NOTIFY_ADAPT = "PAYMENT_NOTIFY_ADAPT";
    public static final String PAY_OWE_FEE_NOTIFY_ADAPT = "PAY_OWE_FEE_NOTIFY_ADAPT";
    public static final String wxMicropayUnifiedOrder="https://api.mch.weixin.qq.com/pay/micropay";
service-acct/src/main/java/com/java110/acct/cmd/payment/UnifiedPaymentCmd.java
New file
@@ -0,0 +1,136 @@
package com.java110.acct.cmd.payment;
import com.alibaba.fastjson.JSONObject;
import com.java110.acct.payment.IPaymentBusiness;
import com.java110.acct.payment.IPaymentFactoryAdapt;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.core.log.LoggerFactory;
import com.java110.doc.annotation.*;
import com.java110.dto.payment.PaymentOrderDto;
import com.java110.utils.cache.CommonCache;
import com.java110.utils.cache.MappingCache;
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.StringUtil;
import org.slf4j.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import java.text.ParseException;
import java.util.Map;
@Java110CmdDoc(title = "统一支付接口",
        description = "系统中的统一支付接口",
        httpMethod = "post",
        url = "http://{ip}:{port}/app/payment.unifiedPayment",
        resource = "acctDoc",
        author = "吴学文",
        serviceCode = "payment.unifiedPayment"
)
@Java110ParamsDoc(params = {
        @Java110ParamDoc(name = "business",length = 64, remark = "支付场景,比如场地预约 为 venueReservation"),
        @Java110ParamDoc(name = "communityId", length = 30, remark = "小区ID"),
        @Java110ParamDoc(name = "tradeType", length = 30, remark = "支付类型 NATIVE JSAPI APP"),
        @Java110ParamDoc(name = "...", length = 30, remark = "其他参数根据相应接口协议传"),
})
@Java110ResponseDoc(
        params = {
                @Java110ParamDoc(name = "code", type = "int", length = 11, defaultValue = "0", remark = "返回编号,0 成功 100 成功不需要唤起支付窗口,直接支付成功,可能从账户等做了扣款,其他失败"),
                @Java110ParamDoc(name = "msg", type = "String", length = 250, defaultValue = "成功", remark = "描述"),
                @Java110ParamDoc(name = "....", type = "String", length = 250, remark = "相应支付厂商要求字段,具体参考 不同厂商协议"),
        }
)
@Java110ExampleDoc(
        reqBody="{\"business\":\"venueReservation\",\"communityId\":\"123123\",\"...\":\"...\"}",
        resBody="{\"code\":0,\"msg\":\"成功\",\"...\":\"...\"}"
)
/**
 * 统一支付接口
 */
@Java110Cmd(serviceCode = "payment.unifiedPayment")
public class UnifiedPaymentCmd extends Cmd{
    private static final Logger logger = LoggerFactory.getLogger(UnifiedPaymentCmd.class);
    protected static final String DEFAULT_PAYMENT_ADAPT = "wechatPaymentAdapt";// 默认微信通用支付
    /**
     * 校验
     * @param event              事件对象
     * @param context 请求报文数据
     * @param reqJson
     * @throws CmdException
     */
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        Assert.hasKeyAndValue(reqJson,"business","未包含业务");
    }
    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
        logger.debug(">>>>>>>>>>>>>>>>支付参数报文,{}",reqJson.toJSONString());
        //1.0 查询当前支付的业务
        IPaymentBusiness paymentBusiness = ApplicationContextFactory.getBean(reqJson.getString("business"), IPaymentBusiness.class);
        if(paymentBusiness == null){
            throw new CmdException("当前支付业务不支持");
        }
        //2.0 相应业务 下单 返回 单号 ,金额,
        PaymentOrderDto paymentOrderDto =  paymentBusiness.unified(reqJson);
        logger.debug(">>>>>>>>>>>>>>>>支付业务下单返回,{}",JSONObject.toJSONString(paymentOrderDto));
        // 3.0 如果支付金额为0 直接调用 支付完通知接口
        if (paymentOrderDto.getMoney() <= 0) {
            paymentBusiness.notifyPayment(paymentOrderDto,reqJson);
            JSONObject param = new JSONObject();
            param.put("code", "100");
            param.put("msg", "扣费为0回调成功");
            context.setResponseEntity(new ResponseEntity(JSONObject.toJSONString(param), HttpStatus.OK));
            return ;
        }
        // 3.0 寻找当前支付适配器
        String payAdapt = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, WechatConstant.PAYMENT_ADAPT);
        payAdapt = StringUtil.isEmpty(payAdapt) ? DEFAULT_PAYMENT_ADAPT : payAdapt;
        IPaymentFactoryAdapt tPayAdapt = ApplicationContextFactory.getBean(payAdapt, IPaymentFactoryAdapt.class);
        // 4.0 相应支付厂家下单
        Map result = null;
        try {
            result = tPayAdapt.java110Payment(paymentOrderDto,reqJson, context);
        } catch (Exception e) {
            logger.error("支付异常",e);
            throw new CmdException(e.getLocalizedMessage());
        }
        ResponseEntity<String> responseEntity = new ResponseEntity(JSONObject.toJSONString(result), HttpStatus.OK);
        logger.debug("调用支付厂家返回,{}",responseEntity);
        context.setResponseEntity(responseEntity);
        // redis 中 保存 请求参数
        CommonCache.setValue("unifiedPayment_"+paymentOrderDto.getOrderId(),reqJson.toJSONString(),CommonCache.PAY_DEFAULT_EXPIRE_TIME);
    }
}
service-acct/src/main/java/com/java110/acct/payment/.DS_Store
Binary files differ
service-acct/src/main/java/com/java110/acct/payment/IPaymentBusiness.java
New file
@@ -0,0 +1,24 @@
package com.java110.acct.payment;
import com.alibaba.fastjson.JSONObject;
import com.java110.dto.payment.PaymentOrderDto;
/**
 * 业务统一下单接口
 */
public interface IPaymentBusiness {
    /**
     * 统一下单
     * @param reqJson
     * @return
     */
    PaymentOrderDto unified(JSONObject reqJson);
    /**
     * 支付完通知接口
     * @param paymentOrderDto
     */
    void notifyPayment(PaymentOrderDto paymentOrderDto, JSONObject reqJson);
}
service-acct/src/main/java/com/java110/acct/payment/IPaymentFactoryAdapt.java
New file
@@ -0,0 +1,23 @@
package com.java110.acct.payment;
import com.alibaba.fastjson.JSONObject;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.dto.payment.PaymentOrderDto;
import java.util.Map;
public interface IPaymentFactoryAdapt {
    /**
     * 支付
     * @param paymentOrderDto
     * @return
     */
    Map java110Payment(PaymentOrderDto paymentOrderDto, JSONObject reqJson,ICmdDataFlowContext context) throws Exception;
    /**
     * 支付完成通知
     * @param param
     * @return
     */
    PaymentOrderDto java110NotifyPayment(String param);
}
service-acct/src/main/java/com/java110/acct/payment/adapt/package-info.java
New file
@@ -0,0 +1,7 @@
/**
 * 支付厂家实现 适配器
 *
 *
 *
 */
package com.java110.acct.payment.adapt;
service-acct/src/main/java/com/java110/acct/payment/adapt/wechat/WechatPaymentFactoryAdapt.java
New file
@@ -0,0 +1,295 @@
package com.java110.acct.payment.adapt.wechat;
import com.alibaba.fastjson.JSONObject;
import com.java110.acct.payment.IPaymentFactoryAdapt;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.factory.WechatFactory;
import com.java110.core.log.LoggerFactory;
import com.java110.dto.app.AppDto;
import com.java110.dto.owner.OwnerAppUserDto;
import com.java110.dto.payment.PaymentOrderDto;
import com.java110.dto.smallWeChat.SmallWeChatDto;
import com.java110.intf.store.ISmallWechatV1InnerServiceSMO;
import com.java110.intf.user.IOwnerAppUserInnerServiceSMO;
import com.java110.utils.cache.MappingCache;
import com.java110.utils.constant.WechatConstant;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.PayUtil;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
/**
 * 微信支付厂家类
 * <p>
 * 微信官方原生 支付实现类
 */
@Service("wechatPaymentFactory")
public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt {
    private static final Logger logger = LoggerFactory.getLogger(WechatPaymentFactoryAdapt.class);
    //微信支付
    public static final String DOMAIN_WECHAT_PAY = "WECHAT_PAY";
    // 微信服务商支付开关
    public static final String WECHAT_SERVICE_PAY_SWITCH = "WECHAT_SERVICE_PAY_SWITCH";
    //开关ON打开
    public static final String WECHAT_SERVICE_PAY_SWITCH_ON = "ON";
    private static final String WECHAT_SERVICE_APP_ID = "SERVICE_APP_ID";
    private static final String WECHAT_SERVICE_MCH_ID = "SERVICE_MCH_ID";
    public static final String TRADE_TYPE_NATIVE = "NATIVE";
    public static final String TRADE_TYPE_JSAPI = "JSAPI";
    public static final String TRADE_TYPE_MWEB = "MWEB";
    public static final String TRADE_TYPE_APP = "APP";
    public static final String wxPayUnifiedOrder = "https://api.mch.weixin.qq.com/pay/unifiedorder";
    @Autowired
    private ISmallWechatV1InnerServiceSMO smallWechatV1InnerServiceSMOImpl;
    @Autowired
    private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMOImpl;
    @Autowired
    private RestTemplate outRestTemplate;
    @Override
    public Map java110Payment(PaymentOrderDto paymentOrderDto, JSONObject reqJson, ICmdDataFlowContext context) throws Exception {
        SmallWeChatDto smallWeChatDto = getSmallWechat(reqJson);
        String appId = context.getReqHeaders().get("app-id");
        String userId = context.getReqHeaders().get("user-id");
        String tradeType = reqJson.getString("tradeType");
        String notifyUrl = MappingCache.getValue("OWNER_WECHAT_URL")+"/app/payment/notify/wechat/992020011134400001";
        String appType = OwnerAppUserDto.APP_TYPE_WECHAT_MINA;
        if (AppDto.WECHAT_OWNER_APP_ID.equals(appId)) {
            appType = OwnerAppUserDto.APP_TYPE_WECHAT;
        } else if (AppDto.WECHAT_MINA_OWNER_APP_ID.equals(appId)) {
            appType = OwnerAppUserDto.APP_TYPE_WECHAT_MINA;
        } else {
            appType = OwnerAppUserDto.APP_TYPE_APP;
        }
        OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
        ownerAppUserDto.setUserId(userId);
        ownerAppUserDto.setAppType(appType);
        List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
        Assert.listOnlyOne(ownerAppUserDtos, "未找到开放账号信息");
        logger.debug("【小程序支付】 统一下单开始, 订单编号=" + paymentOrderDto.getOrderId());
        SortedMap<String, String> resultMap = new TreeMap<String, String>();
        //生成支付金额,开发环境处理支付金额数到0.01、0.02、0.03元
        double payAmount = PayUtil.getPayAmountByEnv(MappingCache.getValue("HC_ENV"), paymentOrderDto.getMoney());
        //添加或更新支付记录(参数跟进自己业务需求添加)
        Map<String, String> resMap = null;
        resMap = this.java110UnifieldOrder(paymentOrderDto.getName(),
                paymentOrderDto.getOrderId(),
                tradeType,
                payAmount,
                ownerAppUserDtos.get(0).getOpenId(),
                smallWeChatDto,
                notifyUrl
        );
        if ("SUCCESS".equals(resMap.get("return_code")) && "SUCCESS".equals(resMap.get("result_code"))) {
            if (TRADE_TYPE_JSAPI.equals(tradeType)) {
                resultMap.put("appId", smallWeChatDto.getAppId());
                resultMap.put("timeStamp", PayUtil.getCurrentTimeStamp());
                resultMap.put("nonceStr", PayUtil.makeUUID(32));
                resultMap.put("package", "prepay_id=" + resMap.get("prepay_id"));
                resultMap.put("signType", "MD5");
                resultMap.put("sign", PayUtil.createSign(resultMap, smallWeChatDto.getPayPassword()));
            } else if (TRADE_TYPE_APP.equals(tradeType)) {
                resultMap.put("appId", smallWeChatDto.getAppId());
                resultMap.put("timeStamp", PayUtil.getCurrentTimeStamp());
                resultMap.put("nonceStr", PayUtil.makeUUID(32));
                resultMap.put("partnerid", smallWeChatDto.getMchId());
                resultMap.put("prepayid", resMap.get("prepay_id"));
                //resultMap.put("signType", "MD5");
                resultMap.put("sign", PayUtil.createSign(resultMap, smallWeChatDto.getPayPassword()));
            } else if (TRADE_TYPE_NATIVE.equals(tradeType)) {
                resultMap.put("prepayId", resMap.get("prepay_id"));
                resultMap.put("codeUrl", resMap.get("code_url"));
            }
            resultMap.put("code", "0");
            resultMap.put("msg", "下单成功");
            logger.info("【小程序支付】统一下单成功,返回参数:" + resultMap + "===notifyUrl===" + notifyUrl);
        } else {
            resultMap.put("code", resMap.get("return_code"));
            resultMap.put("msg", resMap.get("return_msg"));
            logger.info("【小程序支付】统一下单失败,失败原因:" + resMap.get("return_msg") + "===code===" + resMap.get("return_code") + "===notifyUrl===" + notifyUrl);
        }
        return resultMap;
    }
    private Map<String, String> java110UnifieldOrder(String feeName, String orderNum,
                                                     String tradeType, double payAmount, String openid,
                                                     SmallWeChatDto smallWeChatDto, String notifyUrl) throws Exception {
        //String systemName = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, WechatConstant.PAY_GOOD_NAME);
        if (feeName.length() > 127) {
            feeName = feeName.substring(0, 126);
        }
        SortedMap<String, String> paramMap = new TreeMap<String, String>();
        paramMap.put("appid", smallWeChatDto.getAppId());
        paramMap.put("mch_id", smallWeChatDto.getMchId());
        paramMap.put("nonce_str", PayUtil.makeUUID(32));
        paramMap.put("body", feeName);
        paramMap.put("out_trade_no", orderNum);
        paramMap.put("total_fee", PayUtil.moneyToIntegerStr(payAmount));
        paramMap.put("spbill_create_ip", PayUtil.getLocalIp());
        paramMap.put("notify_url", notifyUrl + "?wId=" + WechatFactory.getWId(smallWeChatDto.getAppId()));
        paramMap.put("trade_type", tradeType);
        paramMap.put("openid", openid);
        String paySwitch = MappingCache.getValue(DOMAIN_WECHAT_PAY, WECHAT_SERVICE_PAY_SWITCH);
        if (WECHAT_SERVICE_PAY_SWITCH_ON.equals(paySwitch)) {
            paramMap.put("appid", MappingCache.getValue(DOMAIN_WECHAT_PAY, WECHAT_SERVICE_APP_ID));  //服务商appid,是服务商注册时公众号的id
            paramMap.put("mch_id", MappingCache.getValue(DOMAIN_WECHAT_PAY, WECHAT_SERVICE_MCH_ID));  //服务商商户号
            paramMap.put("sub_appid", smallWeChatDto.getAppId());//起调小程序appid
            paramMap.put("sub_mch_id", smallWeChatDto.getMchId());//起调小程序的商户号
            paramMap.put("sub_openid", openid);
            paramMap.remove("openid");
        }
        paramMap.put("sign", PayUtil.createSign(paramMap, smallWeChatDto.getPayPassword()));
//转换为xml
        String xmlData = PayUtil.mapToXml(paramMap);
        logger.debug("调用支付统一下单接口" + xmlData);
        ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(
                wxPayUnifiedOrder, xmlData, String.class);
        logger.debug("统一下单返回" + responseEntity);
//请求微信后台,获取预支付ID
        if (responseEntity.getStatusCode() != HttpStatus.OK) {
            throw new IllegalArgumentException("支付失败" + responseEntity.getBody());
        }
        return PayUtil.xmlStrToMap(responseEntity.getBody());
    }
    @Override
    public PaymentOrderDto java110NotifyPayment(String param) {
        String resXml = "";
        PaymentOrderDto paymentOrderDto = new PaymentOrderDto();
        try {
            Map<String, Object> map = PayUtil.getMapFromXML(param);
            logger.info("【小程序支付回调】 回调数据: \n" + map);
            String returnCode = (String) map.get("return_code");
            if ("SUCCESS".equalsIgnoreCase(returnCode)) {
                String returnmsg = (String) map.get("result_code");
                if ("SUCCESS".equals(returnmsg)) {
                    //更新数据
                    int result = confirmPayFee(map, paymentOrderDto);
                    if (result > 0) {
                        //支付成功
                        resXml = "<xml>" + "<return_code><![CDATA[SUCCESS]]></return_code>"
                                + "<return_msg><![CDATA[OK]]></return_msg>" + "</xml>";
                    }
                } else {
                    resXml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>"
                            + "<return_msg><![CDATA[报文为空]></return_msg>" + "</xml>";
                    logger.info("支付失败:" + resXml);
                }
            } else {
                resXml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>"
                        + "<return_msg><![CDATA[报文为空]></return_msg>" + "</xml>";
                logger.info("【订单支付失败】");
            }
        } catch (Exception e) {
            logger.error("通知失败", e);
            resXml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>"
                    + "<return_msg><![CDATA[鉴权失败]></return_msg>" + "</xml>";
        }
        paymentOrderDto.setResponseEntity(new ResponseEntity<String>(resXml, HttpStatus.OK));
        return paymentOrderDto;
    }
    public int confirmPayFee(Map<String, Object> map, PaymentOrderDto paymentOrderDto) {
        String appId;
        //兼容 港币交易时 或者微信有时不会掉参数的问题
        if (map.containsKey("wId")) {
            String wId = map.get("wId").toString();
            wId = wId.replace(" ", "+");
            appId = WechatFactory.getAppId(wId);
        } else {
            appId = map.get("appid").toString();
        }
        SortedMap<String, String> paramMap = new TreeMap<String, String>();
        ResponseEntity<String> responseEntity = null;
        for (String key : map.keySet()) {
            if ("wId".equals(key)) {
                continue;
            }
            paramMap.put(key, map.get(key).toString());
        }
        //String appId = WechatFactory.getAppId(wId);
        JSONObject paramIn = new JSONObject();
        paramIn.put("appId", appId);
        SmallWeChatDto smallWeChatDto = getSmallWechat(paramIn);
        String sign = PayUtil.createSign(paramMap, smallWeChatDto.getPayPassword());
        if (!sign.equals(map.get("sign"))) {
            throw new IllegalArgumentException("鉴权失败");
        }
        String outTradeNo = map.get("out_trade_no").toString();
        paymentOrderDto.setOrderId(outTradeNo);
        return 1;
    }
    private SmallWeChatDto getSmallWechat(JSONObject paramIn) {
        SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
        smallWeChatDto.setObjId(paramIn.getString("communityId"));
        smallWeChatDto.setAppId(paramIn.getString("appId"));
        smallWeChatDto.setPage(1);
        smallWeChatDto.setRow(1);
        List<SmallWeChatDto> smallWeChatDtos = smallWechatV1InnerServiceSMOImpl.querySmallWechats(smallWeChatDto);
        if (smallWeChatDtos == null || smallWeChatDtos.size() < 1) {
            smallWeChatDto = new SmallWeChatDto();
            smallWeChatDto.setAppId(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appId"));
            smallWeChatDto.setAppSecret(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appSecret"));
            smallWeChatDto.setMchId(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "mchId"));
            smallWeChatDto.setPayPassword(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "key"));
            return smallWeChatDto;
        }
        return BeanConvertUtil.covertBean(smallWeChatDtos.get(0), SmallWeChatDto.class);
    }
}
service-acct/src/main/java/com/java110/acct/payment/business/.DS_Store
Binary files differ
service-acct/src/main/java/com/java110/acct/payment/business/package-info.java
New file
@@ -0,0 +1,16 @@
/**
 * 支付模块
 *
 * 这个package 写 业务下单实现模块 代码
 * 主要实现
 * IPaymentBusiness 类
 *
 * PaymentOrderDto unified(JSONObject reqJson); 下单处理类 reqjson 前台传送的
 * paymentOrderDto 需要 下单后返回的 对象 主要 包含订单号orderId money 名称
 *
 *  void notify(PaymentOrderDto paymentOrderDto); 支付成功 支付厂家 回调后会通知改方法,接下来业务测可以确认订单
 *
 *
 * add by 吴学文 2022-10-04
 */
package com.java110.acct.payment.business;
service-acct/src/main/java/com/java110/acct/payment/business/venue/VenueReservationPaymentBusiness.java
New file
@@ -0,0 +1,128 @@
package com.java110.acct.payment.business.venue;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.acct.payment.IPaymentBusiness;
import com.java110.core.factory.GenerateCodeFactory;
import com.java110.dto.communitySpace.CommunitySpaceDto;
import com.java110.dto.communitySpacePerson.CommunitySpacePersonDto;
import com.java110.dto.communitySpacePersonTime.CommunitySpacePersonTimeDto;
import com.java110.dto.payment.PaymentOrderDto;
import com.java110.intf.community.ICommunitySpacePersonTimeV1InnerServiceSMO;
import com.java110.intf.community.ICommunitySpacePersonV1InnerServiceSMO;
import com.java110.intf.community.ICommunitySpaceV1InnerServiceSMO;
import com.java110.po.communitySpacePerson.CommunitySpacePersonPo;
import com.java110.po.communitySpacePersonTime.CommunitySpacePersonTimePo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
/**
 * 场地预约
 */
@Service("venueReservation")
public class VenueReservationPaymentBusiness implements IPaymentBusiness{
    @Autowired
    private ICommunitySpaceV1InnerServiceSMO communitySpaceV1InnerServiceSMOImpl;
    public static final String CODE_PREFIX_ID = "10";
    @Autowired
    private ICommunitySpacePersonV1InnerServiceSMO communitySpacePersonV1InnerServiceSMOImpl;
    @Autowired
    private ICommunitySpacePersonTimeV1InnerServiceSMO communitySpacePersonTimeV1InnerServiceSMOImpl;
    @Override
    public PaymentOrderDto unified(JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "spaceId", "请求报文中未包含spaceId");
        Assert.hasKeyAndValue(reqJson, "personName", "请求报文中未包含personName");
        Assert.hasKeyAndValue(reqJson, "personTel", "请求报文中未包含personTel");
        Assert.hasKeyAndValue(reqJson, "appointmentTime", "请求报文中未包含appointmentTime");
        Assert.hasKeyAndValue(reqJson, "receivableAmount", "请求报文中未包含receivableAmount");
        Assert.hasKeyAndValue(reqJson, "receivedAmount", "请求报文中未包含receivedAmount");
        Assert.hasKeyAndValue(reqJson, "payWay", "请求报文中未包含payWay");
        Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中未包含communityId");
        if(!reqJson.containsKey("openTimes")){
            throw new IllegalArgumentException("未包含 预约时间") ;
        }
        JSONArray openTimes = reqJson.getJSONArray("openTimes");
        if(openTimes == null || openTimes.size() <1){
            throw new IllegalArgumentException("未包含 预约时间") ;
        }
        CommunitySpaceDto communitySpaceDto = new CommunitySpaceDto();
        List<CommunitySpaceDto> communitySpaceDtos = communitySpaceV1InnerServiceSMOImpl.queryCommunitySpaces(communitySpaceDto);
        Assert.listOnlyOne(communitySpaceDtos,"场地不存在");
        int openTime = 0;
        for(int timeIndex = 0 ;timeIndex < openTimes.size(); timeIndex++) {
            if("N".equals(openTimes.getJSONObject(timeIndex).getString("isOpen"))){
                continue;
            }
            openTime += 1;
        }
        BigDecimal money = new BigDecimal(openTime).multiply(new BigDecimal(communitySpaceDtos.get(0).getFeeMoney())).setScale(2,BigDecimal.ROUND_HALF_UP);
        PaymentOrderDto paymentOrderDto = new PaymentOrderDto();
        paymentOrderDto.setOrderId(GenerateCodeFactory.getOId());
        paymentOrderDto.setMoney(money.doubleValue());
        paymentOrderDto.setName("预约"+communitySpaceDtos.get(0).getName()+"费用");
        return paymentOrderDto;
    }
    @Override
    public void notifyPayment(PaymentOrderDto paymentOrderDto, JSONObject reqJson) {
        CommunitySpacePersonPo communitySpacePersonPo = BeanConvertUtil.covertBean(reqJson, CommunitySpacePersonPo.class);
        communitySpacePersonPo.setCspId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
        if(StringUtil.isEmpty(communitySpacePersonPo.getState())){
            communitySpacePersonPo.setState(CommunitySpacePersonDto.STATE_W);
        }
        int flag = communitySpacePersonV1InnerServiceSMOImpl.saveCommunitySpacePerson(communitySpacePersonPo);
        if (flag < 1) {
            throw new CmdException("保存数据失败");
        }
        if(!reqJson.containsKey("openTimes")){
            return ;
        }
        JSONArray openTimes = reqJson.getJSONArray("openTimes");
        if(openTimes == null || openTimes.size() <1){
            return ;
        }
        CommunitySpacePersonTimePo communitySpacePersonTimePo = null;
        for(int timeIndex = 0 ;timeIndex < openTimes.size(); timeIndex++) {
            if("N".equals(openTimes.getJSONObject(timeIndex).getString("isOpen"))){
                continue;
            }
            communitySpacePersonTimePo = new CommunitySpacePersonTimePo();
            communitySpacePersonTimePo.setCommunityId(communitySpacePersonPo.getCommunityId());
            communitySpacePersonTimePo.setCspId(communitySpacePersonPo.getCspId());
            communitySpacePersonTimePo.setHours(openTimes.getJSONObject(timeIndex).getString("hours"));
            communitySpacePersonTimePo.setSpaceId(communitySpacePersonPo.getSpaceId());
            communitySpacePersonTimePo.setTimeId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
            communitySpacePersonTimeV1InnerServiceSMOImpl.saveCommunitySpacePersonTime(communitySpacePersonTimePo);
        }
    }
}
service-acct/src/main/java/com/java110/acct/smo/impl/NotifyPaymentV1InnerServiceSMOImpl.java
New file
@@ -0,0 +1,98 @@
/*
 * Copyright 2017-2020 吴学文 and java110 team.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.java110.acct.smo.impl;
import com.alibaba.fastjson.JSONObject;
import com.java110.acct.dao.IOnlinePayV1ServiceDao;
import com.java110.acct.payment.IPaymentBusiness;
import com.java110.acct.payment.IPaymentFactoryAdapt;
import com.java110.core.annotation.Java110Transactional;
import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.core.log.LoggerFactory;
import com.java110.dto.PageDto;
import com.java110.dto.onlinePay.OnlinePayDto;
import com.java110.dto.payment.PaymentOrderDto;
import com.java110.intf.acct.INotifyPaymentV1InnerServiceSMO;
import com.java110.intf.acct.IOnlinePayV1InnerServiceSMO;
import com.java110.po.onlinePay.OnlinePayPo;
import com.java110.utils.cache.CommonCache;
import com.java110.utils.cache.MappingCache;
import com.java110.utils.constant.WechatConstant;
import com.java110.utils.exception.CmdException;
import com.java110.utils.factory.ApplicationContextFactory;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.StringUtil;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
 * 类表述: 服务之前调用的接口实现类,不对外提供接口能力 只用于接口建调用
 * add by 吴学文 at 2021-12-21 13:05:25 mail: 928255095@qq.com
 * open source address: https://gitee.com/wuxw7/MicroCommunity
 * 官网:http://www.homecommunity.cn
 * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
 * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
 */
@RestController
public class NotifyPaymentV1InnerServiceSMOImpl extends BaseServiceSMO implements INotifyPaymentV1InnerServiceSMO {
    private static final Logger logger = LoggerFactory.getLogger(NotifyPaymentV1InnerServiceSMOImpl.class);
    private static final String DEFAULT_PAYMENT_NOTIFY_ADAPT = "wechatPaymentNotifyAdapt";// 默认微信通用支付
    /**
     * 通知类
     * @param param 数据对象分享
     * @return
     */
    @Override
    public ResponseEntity<String> notifyPayment(@RequestBody String param) {
        String payNotifyAdapt = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, WechatConstant.PAYMENT_ADAPT);
        payNotifyAdapt = StringUtil.isEmpty(payNotifyAdapt) ? DEFAULT_PAYMENT_NOTIFY_ADAPT : payNotifyAdapt;
//支付适配器IPayNotifyAdapt
        logger.debug("适配器:" + payNotifyAdapt);
        IPaymentFactoryAdapt tPayNotifyAdapt = ApplicationContextFactory.getBean(payNotifyAdapt, IPaymentFactoryAdapt.class);
        PaymentOrderDto paymentOrderDto = tPayNotifyAdapt.java110NotifyPayment(param);
        logger.info("【支付回调响应】 响应内容:\n" + paymentOrderDto.getResponseEntity());
        if(StringUtil.isEmpty(paymentOrderDto.getOrderId())){
            return paymentOrderDto.getResponseEntity();
        }
        String paramIn = CommonCache.getAndRemoveValue("unifiedPayment_"+paymentOrderDto.getOrderId());
        JSONObject reqJson = JSONObject.parseObject(paramIn);
        IPaymentBusiness paymentBusiness = ApplicationContextFactory.getBean(reqJson.getString("business"), IPaymentBusiness.class);
        if(paymentBusiness == null){
            throw new CmdException("当前支付业务不支持");
        }
        //2.0 相应业务 下单 返回 单号 ,金额,
        paymentBusiness.notifyPayment(paymentOrderDto,reqJson);
        return paymentOrderDto.getResponseEntity();
    }
}
service-api/src/main/java/com/java110/api/configuration/ServiceConfiguration.java
@@ -25,6 +25,7 @@
        exclusions.append("/callComponent/download/getFile/fileByObjId,");//放开 下载图片也不需要登录
        exclusions.append("/callComponent/upload/uploadVedio/upload,");
        exclusions.append("/app/payment/notify,");//微信支付通知
        exclusions.append("/app/payment/notify/*,");// 通用通知放开
        exclusions.append("/app/payment/notifyChinaUms,");//银联支付回调
        exclusions.append("/app/payment/rentingNotify,");//微信支付通知
        exclusions.append("/app/payment/oweFeeNotify,");//欠费微信支付通知
service-api/src/main/java/com/java110/api/controller/app/payment/NotifyPaymentController.java
New file
@@ -0,0 +1,37 @@
package com.java110.api.controller.app.payment;
import com.java110.api.controller.app.PaymentController;
import com.java110.core.log.LoggerFactory;
import com.java110.intf.acct.INotifyPaymentV1InnerServiceSMO;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping(path = "/app/payment/notify")
public class NotifyPaymentController {
    private final static Logger logger = LoggerFactory.getLogger(NotifyPaymentController.class);
    @Autowired
    private INotifyPaymentV1InnerServiceSMO notifyPaymentV1InnerServiceSMOImpl;
    /**
     * <p>支付回调Api</p>
     *
     * @param request
     * @throws Exception
     */
    @RequestMapping(path = "/common/{appId}", method = RequestMethod.POST)
    public ResponseEntity<String> notify(@RequestBody String postInfo, @PathVariable String appId, HttpServletRequest request) {
        logger.debug("微信支付回调报文" + postInfo);
        return notifyPaymentV1InnerServiceSMOImpl.notifyPayment(postInfo);
    }
}
service-api/src/main/java/com/java110/api/controller/app/payment/wechat/WechatNotifyPaymentController.java
New file
@@ -0,0 +1,36 @@
package com.java110.api.controller.app.payment.wechat;
import com.java110.core.log.LoggerFactory;
import com.java110.intf.acct.INotifyPaymentV1InnerServiceSMO;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping(path = "/app/payment/notify")
public class WechatNotifyPaymentController {
    private final static Logger logger = LoggerFactory.getLogger(WechatNotifyPaymentController.class);
    @Autowired
    private INotifyPaymentV1InnerServiceSMO notifyPaymentV1InnerServiceSMOImpl;
    /**
     * <p>支付回调Api</p>
     *
     * @param request
     * @throws Exception
     */
    @RequestMapping(path = "/wechat/{appId}", method = RequestMethod.POST)
    public ResponseEntity<String> notify(@RequestBody String postInfo, @PathVariable String appId, HttpServletRequest request) {
        logger.debug("微信支付回调报文" + postInfo);
        return notifyPaymentV1InnerServiceSMOImpl.notifyPayment(postInfo);
    }
}
springboot/src/main/java/com/java110/boot/configuration/ServiceConfiguration.java
@@ -25,6 +25,7 @@
        exclusions.append("/callComponent/download/getFile/fileByObjId,");//放开 下载图片也不需要登录
        exclusions.append("/callComponent/upload/uploadVedio/upload,");
        exclusions.append("/app/payment/notify,");//微信支付通知
        exclusions.append("/app/payment/notify/*,");// 通用通知放开
        exclusions.append("/app/payment/notifyChinaUms,");//银联支付回调
        exclusions.append("/app/payment/rentingNotify,");//微信支付通知
        exclusions.append("/app/payment/oweFeeNotify,");//欠费微信支付通知
springboot/src/main/java/com/java110/boot/controller/app/payment/NotifyPaymentController.java
New file
@@ -0,0 +1,35 @@
package com.java110.boot.controller.app.payment;
import com.java110.core.log.LoggerFactory;
import com.java110.intf.acct.INotifyPaymentV1InnerServiceSMO;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping(path = "/app/payment/notify")
public class NotifyPaymentController {
    private final static Logger logger = LoggerFactory.getLogger(NotifyPaymentController.class);
    @Autowired
    private INotifyPaymentV1InnerServiceSMO notifyPaymentV1InnerServiceSMOImpl;
    /**
     * <p>支付回调Api</p>
     *
     * @param request
     * @throws Exception
     */
    @RequestMapping(path = "/common/{appId}", method = RequestMethod.POST)
    public ResponseEntity<String> notify(@RequestBody String postInfo, @PathVariable String appId, HttpServletRequest request) {
        logger.debug("微信支付回调报文" + postInfo);
        return notifyPaymentV1InnerServiceSMOImpl.notifyPayment(postInfo);
    }
}
springboot/src/main/java/com/java110/boot/controller/app/payment/wechat/WechatNotifyPaymentController.java
New file
@@ -0,0 +1,35 @@
package com.java110.boot.controller.app.payment.wechat;
import com.java110.core.log.LoggerFactory;
import com.java110.intf.acct.INotifyPaymentV1InnerServiceSMO;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping(path = "/app/payment/notify")
public class WechatNotifyPaymentController {
    private final static Logger logger = LoggerFactory.getLogger(WechatNotifyPaymentController.class);
    @Autowired
    private INotifyPaymentV1InnerServiceSMO notifyPaymentV1InnerServiceSMOImpl;
    /**
     * <p>支付回调Api</p>
     *
     * @param request
     * @throws Exception
     */
    @RequestMapping(path = "/wechat/{appId}", method = RequestMethod.POST)
    public ResponseEntity<String> notify(@RequestBody String postInfo, @PathVariable String appId, HttpServletRequest request) {
        logger.debug("微信支付回调报文" + postInfo);
        return notifyPaymentV1InnerServiceSMOImpl.notifyPayment(postInfo);
    }
}