admin
2021-02-06 d1f26741bddf6f512d62c0100d42c52be8d37e76
工具类优化
4个文件已修改
3个文件已添加
516 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/service/impl/money/TeamRewardDebtServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java 30 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/money/TeamRewardDebtService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/src/main/java/org/yeshi/utils/SPELExpressionUtil.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/src/main/java/org/yeshi/utils/annotation/RequestSerializableByKey.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/src/main/java/org/yeshi/utils/entity/wx/WXPayOrderInfoV3.java 391 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/src/main/java/org/yeshi/utils/wx/WXPayV3Util.java 49 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/money/TeamRewardDebtServiceImpl.java
@@ -45,7 +45,7 @@
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void repayDebt(Long debtId, BigDecimal money) throws TeamRewardDebtException {
    public void repayDebt(Long debtId, BigDecimal money, String beizhu) throws TeamRewardDebtException {
        TeamRewardDebt debt = teamRewardDebtMapper.selectByPrimaryKeyForUpdate(debtId);
        if (debt == null)
            throw new TeamRewardDebtException(1, "债务ID不存在");
@@ -65,6 +65,7 @@
        record.setDebt(debt);
        record.setMoney(money);
        record.setUid(debt.getUid());
        record.setBeiZhu(beizhu);
        teamRewardDebtRepayHistoryMapper.insertSelective(record);
        //还钱是否还完
        if (update.getLeftMoney().compareTo(new BigDecimal(0)) <= 0) {
@@ -99,7 +100,7 @@
            else
                repayMoney = debt.getLeftMoney();
            try {
                repayDebt(debt.getId(), repayMoney);
                repayDebt(debt.getId(), repayMoney,null);
                leftMoney = leftMoney.subtract(repayMoney);
            } catch (TeamRewardDebtException e) {
                // 上笔还款未成功,继续下一笔还款
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java
@@ -112,8 +112,16 @@
    private RocketMQManager rocketMQManager;
    // 下级被封禁,红包失效
    private void invalidHongBaoForbidden(Long id) {
        HongBaoV2 updateHongBaoV2 = new HongBaoV2(id);
    private void invalidHongBaoForbidden(HongBaoV2 hongBaoV2) throws TeamRewardDebtException {
        if (hongBaoV2.getState() == HongBaoV2.STATE_SHIXIAO || hongBaoV2.getState() == HongBaoV2.STATE_YILINGQU || hongBaoV2.getState() == HongBaoV2.STATE_LINGQUING)
            return;
        //如果在偿还里面就先偿还,然后再失效
        TeamRewardDebt debt = teamRewardDebtService.selectBySourceId(hongBaoV2.getId());
        if (debt != null && debt.getLeftMoney().compareTo(hongBaoV2.getMoney()) <= 0) {
            teamRewardDebtService.repayDebt(debt.getId(), hongBaoV2.getMoney(), "封禁失效,先偿还再失效");
        }
        HongBaoV2 updateHongBaoV2 = new HongBaoV2(hongBaoV2.getId());
        updateHongBaoV2.setState(HongBaoV2.STATE_SHIXIAO);
        updateHongBaoV2.setBeizhu("封禁失效");
        updateHongBaoV2.setUpdateTime(new Date());
@@ -125,7 +133,7 @@
    public void inviteSettleTB(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
        // 查询UID的一二级邀请赚
        int sourceType = Constant.SOURCE_TYPE_TAOBAO;
        inviteSettle(uid,sourceType,maxPregetTime);
        inviteSettle(uid, sourceType, maxPregetTime);
    }
    @Transactional(rollbackFor = Exception.class)
@@ -133,7 +141,7 @@
    public void inviteSettleJD(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
        // 查询UID的一二级邀请赚
        int sourceType = Constant.SOURCE_TYPE_JD;
        inviteSettle(uid,sourceType,maxPregetTime);
        inviteSettle(uid, sourceType, maxPregetTime);
    }
    @Transactional(rollbackFor = Exception.class)
@@ -141,7 +149,7 @@
    public void inviteSettlePDD(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
        // 查询UID的一二级邀请赚
        int sourceType = Constant.SOURCE_TYPE_PDD;
        inviteSettle(uid,sourceType,maxPregetTime);
        inviteSettle(uid, sourceType, maxPregetTime);
    }
    @Transactional(rollbackFor = Exception.class)
@@ -149,7 +157,7 @@
    public void inviteSettleVipShop(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
        // 查询UID的一二级邀请赚
        int sourceType = Constant.SOURCE_TYPE_VIP;
        inviteSettle(uid,sourceType,maxPregetTime);
        inviteSettle(uid, sourceType, maxPregetTime);
    }
@@ -158,7 +166,7 @@
    public void inviteSettleSuning(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
        // 查询UID的一二级邀请赚
        int sourceType = Constant.SOURCE_TYPE_SUNING;
        inviteSettle(uid,sourceType,maxPregetTime);
        inviteSettle(uid, sourceType, maxPregetTime);
    }
@@ -190,7 +198,11 @@
                        // 上级用户不是正常用户,订单均不能到账
                        UserInfo userInfo = userInfoMapper.selectAvailableByPrimaryKey(co.getUserInfo().getId());
                        if (userInfo == null || userInfo.getState() != UserInfo.STATE_NORMAL) {
                            invalidHongBaoForbidden(item.getId());
                            try {
                                invalidHongBaoForbidden(item);
                            } catch (TeamRewardDebtException e) {
                                throw new OrderMoneySettleException(10, "偿还出错");
                            }
                            hongBaoList.remove(i);
                            i--;
                        }
@@ -535,7 +547,7 @@
                        && money.compareTo(debt.getLeftMoney()) >= 0) {
                    money = money.subtract(debt.getLeftMoney());
                    // 还钱
                    teamRewardDebtService.repayDebt(debt.getId(), debt.getLeftMoney());
                    teamRewardDebtService.repayDebt(debt.getId(), debt.getLeftMoney(), null);
                }
                invitemoney = invitemoney.add(money);
fanli/src/main/java/com/yeshi/fanli/service/inter/money/TeamRewardDebtService.java
@@ -23,7 +23,7 @@
     * @param debtId
     * @param money
     */
    public void repayDebt(Long debtId, BigDecimal money) throws TeamRewardDebtException;
    public void repayDebt(Long debtId, BigDecimal money,String beizhu) throws TeamRewardDebtException;
    /**
     * 还款
utils/src/main/java/org/yeshi/utils/SPELExpressionUtil.java
New file
@@ -0,0 +1,28 @@
package org.yeshi.utils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
public class SPELExpressionUtil {
    private static ExpressionParser parser = new SpelExpressionParser();
    public static String generateKeyBySpEL(String spELString, ProceedingJoinPoint joinPoint) {
        DefaultParameterNameDiscoverer nameDiscoverer = new DefaultParameterNameDiscoverer();
        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
        String[] paramNames = nameDiscoverer.getParameterNames(methodSignature.getMethod());
        Expression expression = parser.parseExpression(spELString);
        EvaluationContext context = new StandardEvaluationContext();
        Object[] args = joinPoint.getArgs();
        for (int i = 0; i < args.length; i++) {
            context.setVariable(paramNames[i], args[i]);
        }
        return expression.getValue(context).toString();
    }
}
utils/src/main/java/org/yeshi/utils/annotation/RequestSerializableByKey.java
New file
@@ -0,0 +1,11 @@
package org.yeshi.utils.annotation;
import java.lang.annotation.*;
@Documented
@Target(ElementType.METHOD)
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface RequestSerializableByKey {
    String key();
}
utils/src/main/java/org/yeshi/utils/entity/wx/WXPayOrderInfoV3.java
New file
@@ -0,0 +1,391 @@
package org.yeshi.utils.entity.wx;
import java.util.List;
public class WXPayOrderInfoV3 {
    /**
     * transaction_id : 1217752501201407033233368018
     * amount : {"payer_total":100,"total":100,"currency":"CNY","payer_currency":"CNY"}
     * mchid : 1230000109
     * trade_state : SUCCESS
     * bank_type : CMC
     * promotion_detail : [{"amount":100,"wechatpay_contribute":0,"coupon_id":"109519","scope":"GLOBAL","merchant_contribute":0,"name":"单品惠-6","other_contribute":0,"currency":"CNY","stock_id":"931386","goods_detail":[{"goods_remark":"商品备注信息","quantity":1,"discount_amount":1,"goods_id":"M1006","unit_price":100},{"goods_remark":"商品备注信息","quantity":1,"discount_amount":1,"goods_id":"M1006","unit_price":100}]},{"amount":100,"wechatpay_contribute":0,"coupon_id":"109519","scope":"GLOBAL","merchant_contribute":0,"name":"单品惠-6","other_contribute":0,"currency":"CNY","stock_id":"931386","goods_detail":[{"goods_remark":"商品备注信息","quantity":1,"discount_amount":1,"goods_id":"M1006","unit_price":100},{"goods_remark":"商品备注信息","quantity":1,"discount_amount":1,"goods_id":"M1006","unit_price":100}]}]
     * success_time : 2018-06-08T10:34:56+08:00
     * payer : {"openid":"oUpF8uMuAJO_M2pxb1Q9zNjWeS6o"}
     * out_trade_no : 1217752501201407033233368018
     * appid : wxd678efh567hg6787
     * trade_state_desc : 支付失败,请重新下单支付
     * trade_type : MICROPAY
     * attach : 自定义数据
     * scene_info : {"device_id":"013467007045764"}
     */
    private String transaction_id;
    private AmountBean amount;
    private String mchid;
    private String trade_state;
    private String bank_type;
    private String success_time;
    private PayerBean payer;
    private String out_trade_no;
    private String appid;
    private String trade_state_desc;
    private String trade_type;
    private String attach;
    private SceneInfoBean scene_info;
    private List<PromotionDetailBean> promotion_detail;
    public String getTransaction_id() {
        return transaction_id;
    }
    public void setTransaction_id(String transaction_id) {
        this.transaction_id = transaction_id;
    }
    public AmountBean getAmount() {
        return amount;
    }
    public void setAmount(AmountBean amount) {
        this.amount = amount;
    }
    public String getMchid() {
        return mchid;
    }
    public void setMchid(String mchid) {
        this.mchid = mchid;
    }
    public String getTrade_state() {
        return trade_state;
    }
    public void setTrade_state(String trade_state) {
        this.trade_state = trade_state;
    }
    public String getBank_type() {
        return bank_type;
    }
    public void setBank_type(String bank_type) {
        this.bank_type = bank_type;
    }
    public String getSuccess_time() {
        return success_time;
    }
    public void setSuccess_time(String success_time) {
        this.success_time = success_time;
    }
    public PayerBean getPayer() {
        return payer;
    }
    public void setPayer(PayerBean payer) {
        this.payer = payer;
    }
    public String getOut_trade_no() {
        return out_trade_no;
    }
    public void setOut_trade_no(String out_trade_no) {
        this.out_trade_no = out_trade_no;
    }
    public String getAppid() {
        return appid;
    }
    public void setAppid(String appid) {
        this.appid = appid;
    }
    public String getTrade_state_desc() {
        return trade_state_desc;
    }
    public void setTrade_state_desc(String trade_state_desc) {
        this.trade_state_desc = trade_state_desc;
    }
    public String getTrade_type() {
        return trade_type;
    }
    public void setTrade_type(String trade_type) {
        this.trade_type = trade_type;
    }
    public String getAttach() {
        return attach;
    }
    public void setAttach(String attach) {
        this.attach = attach;
    }
    public SceneInfoBean getScene_info() {
        return scene_info;
    }
    public void setScene_info(SceneInfoBean scene_info) {
        this.scene_info = scene_info;
    }
    public List<PromotionDetailBean> getPromotion_detail() {
        return promotion_detail;
    }
    public void setPromotion_detail(List<PromotionDetailBean> promotion_detail) {
        this.promotion_detail = promotion_detail;
    }
    public static class AmountBean {
        /**
         * payer_total : 100
         * total : 100
         * currency : CNY
         * payer_currency : CNY
         */
        private int payer_total;
        private int total;
        private String currency;
        private String payer_currency;
        public int getPayer_total() {
            return payer_total;
        }
        public void setPayer_total(int payer_total) {
            this.payer_total = payer_total;
        }
        public int getTotal() {
            return total;
        }
        public void setTotal(int total) {
            this.total = total;
        }
        public String getCurrency() {
            return currency;
        }
        public void setCurrency(String currency) {
            this.currency = currency;
        }
        public String getPayer_currency() {
            return payer_currency;
        }
        public void setPayer_currency(String payer_currency) {
            this.payer_currency = payer_currency;
        }
    }
    public static class PayerBean {
        /**
         * openid : oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
         */
        private String openid;
        public String getOpenid() {
            return openid;
        }
        public void setOpenid(String openid) {
            this.openid = openid;
        }
    }
    public static class SceneInfoBean {
        /**
         * device_id : 013467007045764
         */
        private String device_id;
        public String getDevice_id() {
            return device_id;
        }
        public void setDevice_id(String device_id) {
            this.device_id = device_id;
        }
    }
    public static class PromotionDetailBean {
        /**
         * amount : 100
         * wechatpay_contribute : 0
         * coupon_id : 109519
         * scope : GLOBAL
         * merchant_contribute : 0
         * name : 单品惠-6
         * other_contribute : 0
         * currency : CNY
         * stock_id : 931386
         * goods_detail : [{"goods_remark":"商品备注信息","quantity":1,"discount_amount":1,"goods_id":"M1006","unit_price":100},{"goods_remark":"商品备注信息","quantity":1,"discount_amount":1,"goods_id":"M1006","unit_price":100}]
         */
        private int amount;
        private int wechatpay_contribute;
        private String coupon_id;
        private String scope;
        private int merchant_contribute;
        private String name;
        private int other_contribute;
        private String currency;
        private String stock_id;
        private List<GoodsDetailBean> goods_detail;
        public int getAmount() {
            return amount;
        }
        public void setAmount(int amount) {
            this.amount = amount;
        }
        public int getWechatpay_contribute() {
            return wechatpay_contribute;
        }
        public void setWechatpay_contribute(int wechatpay_contribute) {
            this.wechatpay_contribute = wechatpay_contribute;
        }
        public String getCoupon_id() {
            return coupon_id;
        }
        public void setCoupon_id(String coupon_id) {
            this.coupon_id = coupon_id;
        }
        public String getScope() {
            return scope;
        }
        public void setScope(String scope) {
            this.scope = scope;
        }
        public int getMerchant_contribute() {
            return merchant_contribute;
        }
        public void setMerchant_contribute(int merchant_contribute) {
            this.merchant_contribute = merchant_contribute;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public int getOther_contribute() {
            return other_contribute;
        }
        public void setOther_contribute(int other_contribute) {
            this.other_contribute = other_contribute;
        }
        public String getCurrency() {
            return currency;
        }
        public void setCurrency(String currency) {
            this.currency = currency;
        }
        public String getStock_id() {
            return stock_id;
        }
        public void setStock_id(String stock_id) {
            this.stock_id = stock_id;
        }
        public List<GoodsDetailBean> getGoods_detail() {
            return goods_detail;
        }
        public void setGoods_detail(List<GoodsDetailBean> goods_detail) {
            this.goods_detail = goods_detail;
        }
        public static class GoodsDetailBean {
            /**
             * goods_remark : 商品备注信息
             * quantity : 1
             * discount_amount : 1
             * goods_id : M1006
             * unit_price : 100
             */
            private String goods_remark;
            private int quantity;
            private int discount_amount;
            private String goods_id;
            private int unit_price;
            public String getGoods_remark() {
                return goods_remark;
            }
            public void setGoods_remark(String goods_remark) {
                this.goods_remark = goods_remark;
            }
            public int getQuantity() {
                return quantity;
            }
            public void setQuantity(int quantity) {
                this.quantity = quantity;
            }
            public int getDiscount_amount() {
                return discount_amount;
            }
            public void setDiscount_amount(int discount_amount) {
                this.discount_amount = discount_amount;
            }
            public String getGoods_id() {
                return goods_id;
            }
            public void setGoods_id(String goods_id) {
                this.goods_id = goods_id;
            }
            public int getUnit_price() {
                return unit_price;
            }
            public void setUnit_price(int unit_price) {
                this.unit_price = unit_price;
            }
        }
    }
}
utils/src/main/java/org/yeshi/utils/wx/WXPayV3Util.java
@@ -1,5 +1,6 @@
package org.yeshi.utils.wx;
import com.google.gson.Gson;
import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder;
import com.wechat.pay.contrib.apache.httpclient.auth.AutoUpdateCertificatesVerifier;
import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner;
@@ -17,6 +18,7 @@
import org.apache.http.util.EntityUtils;
import org.yeshi.utils.StringUtil;
import org.yeshi.utils.entity.wx.WXAPPInfo;
import org.yeshi.utils.entity.wx.WXPayOrderInfoV3;
import org.yeshi.utils.entity.wx.WXPlaceOrderParams;
import org.yeshi.utils.exception.WXOrderException;
import org.yeshi.utils.exception.WXPlaceOrderParamsException;
@@ -25,6 +27,7 @@
import java.io.FileInputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.PrivateKey;
@@ -63,8 +66,13 @@
    private static JSONObject request(String url, String requestData, WXAPPInfo app) throws Exception {
        HttpPost httpPost = new HttpPost(url);
        if (StringUtil.isNullOrEmpty(requestData)) {
            requestData = "{}";
        }
        if (!StringUtil.isNullOrEmpty(requestData)) {
            StringEntity entity = new StringEntity(requestData, ContentType.APPLICATION_JSON.withCharset(Charsets.UTF_8));
            StringEntity entity = new StringEntity(requestData, ContentType.APPLICATION_JSON.withCharset(Charset.forName("UTF-8")));
            entity.setContentType("application/json;charset=utf-8");
            httpPost.setEntity(entity);
        }
@@ -163,15 +171,33 @@
     * @throws WXOrderException
     */
    public static boolean isPaySuccess(String orderNo, WXAPPInfo app) throws Exception {
        String url = String.format("https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/%s?mchid=%s", URLEncoder.encode(orderNo), app.getMchId());
        JSONObject result = request(url, null, app);
        if (result == null)
        WXPayOrderInfoV3 info = getPayOrderInfo(orderNo, app);
        if (info == null)
            return false;
        return "SUCCESS".equalsIgnoreCase(result.optString("trade_state"));
        return "SUCCESS".equalsIgnoreCase(info.getTrade_state());
    }
    /**
     * 获取订单信息
     *
     * @param orderNo
     * @param app
     * @return
     * @throws Exception
     */
    public static WXPayOrderInfoV3 getPayOrderInfo(String orderNo, WXAPPInfo app) throws Exception {
        String url = String.format("https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/%s?mchid=%s", URLEncoder.encode(orderNo), app.getMchId());
        JSONObject result = request(url, "", app);
        if (result == null)
            return null;
        return new Gson().fromJson(result.toString(), WXPayOrderInfoV3.class);
    }
    public static void main(String[] args) {
        String privateKey = "";
        try {
            String content = IOUtils.toString(new FileInputStream("D:\\项目\\返利券\\商户平台\\1520950211_20210125_cert\\apiclient_key.pem"));
@@ -181,19 +207,30 @@
        } catch (Exception e) {
        }
        WXAPPInfo app = new WXAPPInfo("wxa99686bb65a9f466", "1520950211", "454328C324C6CC21355D064B44D6524CD7506DD0", privateKey, "XYJkJ2018FAfaodCCx899mLl138rfGVd");
        WXPlaceOrderParams params = new WXPlaceOrderParams();
        params.setBody("影视大全VIP-包月");
        params.setFee(new BigDecimal("0.1"));
        params.setNotifyUrl("http://api.ysdq.yeshitv.com:8089/BuWan/wx/pay/vip");
        params.setOrderNo("buwan-vip-8");
        params.setIp("113.249.192.231");
        params.setApp(new WXAPPInfo("wxa99686bb65a9f466", "1520950211", "454328C324C6CC21355D064B44D6524CD7506DD0", privateKey, "XYJkJ2018FAfaodCCx899mLl138rfGVd"));
        params.setApp(app);
        try {
            String payUrl = WXPayV3Util.createH5Order(params, "http://vip.ysdq.yeshitv.com/wx_result.html");
            System.out.println(payUrl);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            WXPayOrderInfoV3 info = WXPayV3Util.getPayOrderInfo("buwan-vip-8", app);
            System.out.println(info);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}