liujie
3 天以前 a540a342416302805adfb1599599bbbbaa191030
cloud-server-management/src/main/java/com/dsh/guns/modular/system/util/PayMoneyUtil.java
@@ -2,13 +2,6 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeAppPayModel;
import com.alipay.api.msg.AlipayMsgClient;
import com.alipay.api.msg.MsgHandler;
import com.alipay.api.request.*;
import com.alipay.api.response.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -343,75 +336,75 @@
    /**
     * 处理直付通审核通过和拒绝消息
     */
    public void getMessage() {
        System.err.println("进入");
        final AlipayMsgClient alipayMsgClient = AlipayMsgClient.getInstance(aliAppid);
        try {
            alipayMsgClient.setConnector(serverHost);
        } catch (Exception e) {
            e.printStackTrace();
        }
        alipayMsgClient.setSecurityConfig(signType, appPrivateKey, alipay_public_key);
        try {
            alipayMsgClient.connect();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        alipayMsgClient.setMessageHandler( new  MsgHandler() {
            /**
             * 客户端接收到消息后回调此方法
             *  @param  msgApi 接收到的消息的消息api名
             *  @param  msgId 接收到的消息的消息id
             *  @param  bizContent 接收到的消息的内容,json格式
             */
            public   void   onMessage (String msgApi, String msgId, String bizContent)   {
                // 直付通进件审核通过
                if (StringUtils.equals(msgApi,"ant.merchant.expand.indirect.zft.passed")){
                    // 修改运营商状态 将返回的商户号填入运营商
                    System.out.println( "receive message. msgApi:"  + msgApi +  " msgId:"  + msgId +  " bizContent:"  + bizContent);
                    JSONObject json = JSONObject.parseObject(bizContent);
                    // 商户号
                    String smid = json.getString("smid");
                    // 审核备注信息
                    String memo = json.getString("memo");
                    // 订单id
                    String orderId = json.getString("order_id");
                    // 通过订单id查询
                    OperatorAuthAlipay auth = operatorAuthService.getOne(new QueryWrapper<OperatorAuthAlipay>()
                            .eq("orderNo",orderId));
                    auth.setSmid(smid);
                    auth.setAuditState(2);
                    auth.setRefuseReason(memo);
                    operatorAuthService.updateById(auth);
                    Integer operatorId = auth.getOperatorId();
                    OperatorUser operatorId1 = operatorUserService.getOne(new QueryWrapper<OperatorUser>()
                            .eq("operatorId", operatorId));
                    operatorId1.setAlipayNum(smid);
                    operatorId1.setAlipayAudit(2);
                    operatorUserService.updateById(operatorId1);
                }
                // 直付通进件审核失败
                if (StringUtils.equals(msgApi,"ant.merchant.expand.indirect.zft.rejected")){
                    JSONObject json = JSONObject.parseObject(bizContent);
                    // 商户号
                    String orderId = json.getString("order_id");
                    // 官方拒绝理由
                    String reason = json.getString("reason");
                    // 通过订单id查询
                    OperatorAuthAlipay auth = operatorAuthService.getOne(new QueryWrapper<OperatorAuthAlipay>()
                            .eq("orderNo",orderId));
                    auth.setAuditState(3);
                    auth.setRefuseReason(reason);
                    operatorAuthService.updateById(auth);
                    Integer operatorId = auth.getOperatorId();
                    OperatorUser operatorId1 = operatorUserService.getOne(new QueryWrapper<OperatorUser>()
                            .eq("operatorId", operatorId));
                    operatorId1.setAlipayAudit(3);
                    operatorUserService.updateById(operatorId1);
                }
            }
        });
    }
//    public void getMessage() {
//        System.err.println("进入");
//        final AlipayMsgClient alipayMsgClient = AlipayMsgClient.getInstance(aliAppid);
//        try {
//            alipayMsgClient.setConnector(serverHost);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        alipayMsgClient.setSecurityConfig(signType, appPrivateKey, alipay_public_key);
//        try {
//            alipayMsgClient.connect();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        alipayMsgClient.setMessageHandler( new  MsgHandler() {
//            /**
//             * 客户端接收到消息后回调此方法
//             *  @param  msgApi 接收到的消息的消息api名
//             *  @param  msgId 接收到的消息的消息id
//             *  @param  bizContent 接收到的消息的内容,json格式
//             */
//            public   void   onMessage (String msgApi, String msgId, String bizContent)   {
//                // 直付通进件审核通过
//                if (StringUtils.equals(msgApi,"ant.merchant.expand.indirect.zft.passed")){
//                    // 修改运营商状态 将返回的商户号填入运营商
//                    System.out.println( "receive message. msgApi:"  + msgApi +  " msgId:"  + msgId +  " bizContent:"  + bizContent);
//                    JSONObject json = JSONObject.parseObject(bizContent);
//                    // 商户号
//                    String smid = json.getString("smid");
//                    // 审核备注信息
//                    String memo = json.getString("memo");
//                    // 订单id
//                    String orderId = json.getString("order_id");
//                    // 通过订单id查询
//                    OperatorAuthAlipay auth = operatorAuthService.getOne(new QueryWrapper<OperatorAuthAlipay>()
//                            .eq("orderNo",orderId));
//                    auth.setSmid(smid);
//                    auth.setAuditState(2);
//                    auth.setRefuseReason(memo);
//                    operatorAuthService.updateById(auth);
//                    Integer operatorId = auth.getOperatorId();
//                    OperatorUser operatorId1 = operatorUserService.getOne(new QueryWrapper<OperatorUser>()
//                            .eq("operatorId", operatorId));
//                    operatorId1.setAlipayNum(smid);
//                    operatorId1.setAlipayAudit(2);
//                    operatorUserService.updateById(operatorId1);
//                }
//                // 直付通进件审核失败
//                if (StringUtils.equals(msgApi,"ant.merchant.expand.indirect.zft.rejected")){
//                    JSONObject json = JSONObject.parseObject(bizContent);
//                    // 商户号
//                    String orderId = json.getString("order_id");
//                    // 官方拒绝理由
//                    String reason = json.getString("reason");
//                    // 通过订单id查询
//                    OperatorAuthAlipay auth = operatorAuthService.getOne(new QueryWrapper<OperatorAuthAlipay>()
//                            .eq("orderNo",orderId));
//                    auth.setAuditState(3);
//                    auth.setRefuseReason(reason);
//                    operatorAuthService.updateById(auth);
//                    Integer operatorId = auth.getOperatorId();
//                    OperatorUser operatorId1 = operatorUserService.getOne(new QueryWrapper<OperatorUser>()
//                            .eq("operatorId", operatorId));
//                    operatorId1.setAlipayAudit(3);
//                    operatorUserService.updateById(operatorId1);
//                }
//            }
//        });
//    }
    /**
     * 支付宝支付
     */
@@ -468,19 +461,19 @@
//        }
        //实例化客户端
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", aliAppid, appPrivateKey, "json", "UTF-8", alipay_public_key, "RSA2");
        //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
        AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
        //SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
        AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
        model.setBody(body);//对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。
        model.setSubject(subject);//商品的标题/交易标题/订单标题/订单关键字等。
        model.setOutTradeNo(outTradeNo);//商户网站唯一订单号
        model.setTimeoutExpress("30m");
        model.setTotalAmount(amount);//付款金额
        model.setProductCode("QUICK_MSECURITY_PAY");
        model.setPassbackParams(passbackParams);//自定义参数
//        //实例化客户端
//        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", aliAppid, appPrivateKey, "json", "UTF-8", alipay_public_key, "RSA2");
//        //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
//        AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
//        //SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
//        AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
//        model.setBody(body);//对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。
//        model.setSubject(subject);//商品的标题/交易标题/订单标题/订单关键字等。
//        model.setOutTradeNo(outTradeNo);//商户网站唯一订单号
//        model.setTimeoutExpress("30m");
//        model.setTotalAmount(amount);//付款金额
//        model.setProductCode("QUICK_MSECURITY_PAY");
//        model.setPassbackParams(passbackParams);//自定义参数
        //分账
@@ -521,42 +514,42 @@
//        model.setRoyaltyInfo(royaltyInfo);
//        System.err.println("=================="+royaltyInfo);
        //
        request.setBizModel(model);
        request.setNotifyUrl(callbackPath + notifyUrl);
        try {
            //这里和普通的接口调用不同,使用的是sdkExecute
            AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
            Map<String, String> map = new HashMap<>();
            map.put("orderString", response.getBody());
            map.put("returnId", passbackParams);
            System.out.println(map);//就是orderString 可以直接给客户端请求,无需再做处理。
            return ResultUtil.success(map);
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
//        request.setBizModel(model);
//        request.setNotifyUrl(callbackPath + notifyUrl);
//        try {
//            //这里和普通的接口调用不同,使用的是sdkExecute
//            AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
//            Map<String, String> map = new HashMap<>();
//            map.put("orderString", response.getBody());
//            map.put("returnId", passbackParams);
//            System.out.println(map);//就是orderString 可以直接给客户端请求,无需再做处理。
//            return ResultUtil.success(map);
//        } catch (AlipayApiException e) {
//            e.printStackTrace();
//        }
        return null;
    }
    /**
     * 支付宝查询订单支付状态
     *
     * @param out_trade_no
     * @return
     * @throws Exception
     */
    public AlipayTradeQueryResponse queryALIOrder(String out_trade_no) throws Exception {
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", aliAppid, appPrivateKey, "json", "UTF-8", alipay_public_key, "RSA2");
        AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
        request.setBizContent("{" +
                "  \"out_trade_no\":\"" + out_trade_no + "\"" +
                "}");
        AlipayTradeQueryResponse response = alipayClient.execute(request);
        return response;
    }
//    /**
//     * 支付宝查询订单支付状态
//     *
//     * @param out_trade_no
//     * @return
//     * @throws Exception
//     */
//    public AlipayTradeQueryResponse queryALIOrder(String out_trade_no) throws Exception {
//        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", aliAppid, appPrivateKey, "json", "UTF-8", alipay_public_key, "RSA2");
//        AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
//        request.setBizContent("{" +
//                "  \"out_trade_no\":\"" + out_trade_no + "\"" +
//                "}");
//        AlipayTradeQueryResponse response = alipayClient.execute(request);
//        return response;
//
//    }