GOLDEN-TECH\weiyf há 3 anos atrás
pai
commit
c961fd5823

+ 2 - 0
src/main/java/com/parksong/beans/express/RechargeStatistics.java

@@ -29,6 +29,8 @@ public class RechargeStatistics {
     private String remark;
     //充值人员
     private String operator;
+
+    private int id;
     //充值时间
     private Date optTime;
 

+ 4 - 3
src/main/java/com/parksong/controllers/applets/AppletsController.java

@@ -13,6 +13,8 @@ import com.parksong.services.applets.AppletsService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 import java.util.Map;
 
@@ -138,9 +140,8 @@ public class AppletsController {
     //回调地址 需要外网能够访问
     @ApiVersion(1)
     @PostMapping("{version}/recharge/notify_url")
-    public String notifyUrl(@RequestBody WeiXinReceiptBean weiXinReceiptBean) throws Exception {
-        System.out.println(JSONObject.toJSONString(weiXinReceiptBean));
-        //appletsService.notifyUrl(request,response);
+    public String notifyUrl(HttpServletRequest request, HttpServletResponse response) throws Exception {
+        appletsService.notifyUrl(request,response);
         return "";
     }
 

+ 3 - 1
src/main/java/com/parksong/dao/applets/AppletsMapper.java

@@ -23,10 +23,12 @@ public interface AppletsMapper {
 
     int updateDeptAccount(@Param("expressDeptAccount") ExpressDeptAccount expressDeptAccount);
 
-    int insertSelective(RechargeStatistics rechargeStatistics);
+    int insertSelective(@Param("rechargeStatistics") RechargeStatistics rechargeStatistics);
 
     int updateDept(@Param("user") ExpressDept user);
 
+    int updateSelectiveByOutTradeNo(@Param("rechargeStatistics") RechargeStatistics rechargeStatistics);
+
     List<ExpressApplets> expressInfo(@Param("filter") AppletsFilter filter);
 
     Long selectExpressInfoCount(@Param("filter") AppletsFilter filter);

+ 49 - 38
src/main/java/com/parksong/services/applets/impl/AppletsServiceImpl.java

@@ -17,6 +17,7 @@ import com.parksong.util.Http.OkHttpUtil;
 import com.parksong.util.JwtUtils;
 import com.parksong.util.WxPayUtil;
 import com.parksong.util.enums.ExpressStatusEnum;
+import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -29,6 +30,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.BufferedOutputStream;
 import java.io.BufferedReader;
+import java.io.IOException;
 import java.io.InputStreamReader;
 import java.math.BigDecimal;
 import java.time.LocalDate;
@@ -192,9 +194,22 @@ public class AppletsServiceImpl implements AppletsService {
                 .build();
         //返回下单接口
         Map<String, Object> objectMap = wxPayUtil.wxPay(orderPay);
+        if(objectMap.get("appid")!=null){
+            //添加充值记录
+            RechargeStatistics rechargeStatistics = new RechargeStatistics();
+            rechargeStatistics.setAmount(amount);
+            rechargeStatistics.setPayWay("2");
+            rechargeStatistics.setOutTradeNo(out_trade_no);
+            //已付款,待回调确认
+            rechargeStatistics.setPayStatus("0");
+            rechargeStatistics.setAccountId(user.getId().toString());
+            rechargeStatistics.setOperator("admin");
+            appletsMapper.insertSelective(rechargeStatistics);
+        }
         return objectMap;
     }
 
+    @Override
     public Map<String, Object> notifyUrl(HttpServletRequest request, HttpServletResponse response) throws Exception {
 
         log.info("--------------回调开始----------------");
@@ -217,51 +232,47 @@ public class AppletsServiceImpl implements AppletsService {
         //sb为微信返回的xml
         String notityXml = sb.toString();
         String resXml = "";
+        log.info("------notityXml---------:"+notityXml);
         Map map = wxPayUtil.doXMLParse(notityXml);
         String returnCode = (String) map.get("return_code");
         log.info("returnCode:"+returnCode);
         if ("SUCCESS".equals(returnCode)) {
-            //验证签名是否正确
-            Map<String, String> validParams = wxPayUtil.paraFilter(map);
-            //回调验签时需要去除sign和空值参数
-            String prestr = wxPayUtil.createLinkString(validParams);
-            //生成签名
-            String mysign = wxPayUtil.sign(prestr, weChatKey, "utf-8").toUpperCase();
-            //根据微信官网的介绍,此处不仅对回调的参数进行验签,还需要对返回的金额与系统订单的金额进行比对等
-            log.info("----------mysign:"+mysign+"--------------map.get(\"sign\"):"+map.get("sign"));
-            if (mysign.equals(map.get("sign").toString())) {
-
-                String openid = (String) map.get("openid");
-                String cash_fee = (String) map.get("cash_fee");
-                String day = String.format("%02d", LocalDate.now().getDayOfMonth());
-                CacheTool rechargeCacheTool = CacheTool.initrechargeCacheTool();
-                String number = String.format("%06d", rechargeCacheTool.incrBy(day, 1).intValue());
-                BigDecimal amount = new BigDecimal(cash_fee).divide(new BigDecimal(100));
-
-                //根据openid获取用户信息
-                ExpressDept user = appletsMapper.userDetailByOpenId(openid);
-                //添加充值记录
-                RechargeStatistics rechargeStatistics = new RechargeStatistics();
-                rechargeStatistics.setAmount(amount);
-                rechargeStatistics.setPayWay("2");
-                rechargeStatistics.setOutTradeNo(day+number);
-                rechargeStatistics.setPayStatus("1");
-                rechargeStatistics.setAccountId(user.getId().toString());
-                rechargeStatistics.setOperator("admin");
-                int  a = appletsMapper.insertSelective(rechargeStatistics);
-
-                //更新余额
-                ExpressDeptAccount userAccount = new ExpressDeptAccount();
-                userAccount.setId(user.getId());
-                userAccount.setBalance(amount);
-                int b =appletsMapper.updateDeptAccount(userAccount);
-
-                log.info("----------a:"+a+"--------------b:"+b);
-
+            try{
+                //验证签名是否正确
+                Map<String, String> validParams = wxPayUtil.paraFilter(map);
+                //回调验签时需要去除sign和空值参数
+                String prestr = wxPayUtil.createLinkString(validParams);
+                //生成签名
+                String mysign = wxPayUtil.sign(prestr, weChatKey, "utf-8").toUpperCase();
+                //根据微信官网的介绍,此处不仅对回调的参数进行验签,还需要对返回的金额与系统订单的金额进行比对等
+                if (mysign.equals(map.get("sign").toString())) {
+                    String openid = (String) map.get("openid");
+                    String cash_fee = (String) map.get("cash_fee");
+                    String out_trade_no = (String) map.get("out_trade_no");
+                    CacheTool rechargeCacheTool = CacheTool.initrechargeCacheTool();
+                    BigDecimal amount = new BigDecimal(cash_fee).divide(new BigDecimal(100));
+                    //根据openid获取用户信息
+                    ExpressDept user = appletsMapper.userDetailByOpenId(openid);
+                    //添加充值记录
+                    RechargeStatistics rechargeStatistics = new RechargeStatistics();
+                    rechargeStatistics.setOutTradeNo(out_trade_no);
+                    rechargeStatistics.setPayStatus("1");
+                    int a = appletsMapper.updateSelectiveByOutTradeNo(rechargeStatistics);
+                    if(a!=0){
+                        //更新余额
+                        ExpressDeptAccount userAccount = new ExpressDeptAccount();
+                        userAccount.setId(user.getId());
+                        userAccount.setBalance(amount);
+                        int b =appletsMapper.updateDeptAccount(userAccount);
+                    }
+                }
+
+            }catch (Exception ex){
+                log.info("--------exception--------"+ex);
+            }finally {
                 //返回通知微信已经接收到消息
                 resXml = "<xml>" + "<return_code><![CDATA[SUCCESS]]></return_code>"
                         + "<return_msg><![CDATA[OK]]></return_msg>" + "</xml> ";
-
             }
         } else {
             resXml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>"

+ 3 - 2
src/main/resources/application-pro.yml

@@ -125,5 +125,6 @@ wechat:
   weChatKey: YOUBAIMIyoubaimi12345678qwertyui
   appId: wxa81b778220fd83f7
   weChatApi: https://api.weixin.qq.com
-  mch_id: 92a75147cf0f6116c8390c7d7b0708ad
-  shopKey: 1611844958
+  mch_id: 1611844958
+  shopKey: 1611844958
+  secret: fcff3120b3042c6ea377df98c948f70a

+ 37 - 31
src/main/resources/com/parksong/mapper/applets/AppletsMapper.xml

@@ -33,70 +33,70 @@
 
     </update>
 
-    <insert id="insertSelective">
+    <insert id="insertSelective" useGeneratedKeys="true" keyProperty="id">
         insert into t_express_account_recharge_record
         <trim prefix="(" suffix=")" suffixOverrides=",">
-            <if test="id != null">
+            <if test="rechargeStatistics.id != null">
                 id,
             </if>
-            <if test="amount != null">
+            <if test="rechargeStatistics.amount != null">
                 amount,
             </if>
-            <if test="payWay != null">
+            <if test="rechargeStatistics.payWay != null">
                 payWay,
             </if>
-            <if test="outTradeNo != null">
+            <if test="rechargeStatistics.outTradeNo != null">
                 outTradeNo,
             </if>
-            <if test="tradeNo != null">
+            <if test="rechargeStatistics.tradeNo != null">
                 tradeNo,
             </if>
-            <if test="payStatus != null">
+            <if test="rechargeStatistics.payStatus != null">
                 payStatus,
             </if>
-            <if test="accountId != null">
+            <if test="rechargeStatistics.accountId != null">
                 accountId,
             </if>
-            <if test="remark != null">
+            <if test="rechargeStatistics.remark != null">
                 remark,
             </if>
-            <if test="operator != null">
+            <if test="rechargeStatistics.operator != null">
                 operator,
             </if>
-            <if test="optTime != null">
+            <if test="rechargeStatistics.optTime != null">
                 optTime,
             </if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
-            <if test="id != null">
-                #{id,jdbcType=BIGINT},
+            <if test="rechargeStatistics.id != null">
+                #{rechargeStatistics.id,jdbcType=BIGINT},
             </if>
-            <if test="amount != null">
-                #{amount,jdbcType=DECIMAL},
+            <if test="rechargeStatistics.amount != null">
+                #{rechargeStatistics.amount,jdbcType=DECIMAL},
             </if>
-            <if test="payWay != null">
-                #{payWay,jdbcType=INTEGER},
+            <if test="rechargeStatistics.payWay != null">
+                #{rechargeStatistics.payWay,jdbcType=INTEGER},
             </if>
-            <if test="outTradeNo != null">
-                #{outTradeNo,jdbcType=VARCHAR},
+            <if test="rechargeStatistics.outTradeNo != null">
+                #{rechargeStatistics.outTradeNo,jdbcType=VARCHAR},
             </if>
-            <if test="tradeNo != null">
-                #{tradeNo,jdbcType=VARCHAR},
+            <if test="rechargeStatistics.tradeNo != null">
+                #{rechargeStatistics.tradeNo,jdbcType=VARCHAR},
             </if>
-            <if test="payStatus != null">
-                #{payStatus,jdbcType=INTEGER},
+            <if test="rechargeStatistics.payStatus != null">
+                #{rechargeStatistics.payStatus,jdbcType=INTEGER},
             </if>
-            <if test="accountId != null">
-                #{accountId,jdbcType=BIGINT},
+            <if test="rechargeStatistics.accountId != null">
+                #{rechargeStatistics.accountId,jdbcType=BIGINT},
             </if>
-            <if test="remark != null">
-                #{remark,jdbcType=VARCHAR},
+            <if test="rechargeStatistics.remark != null">
+                #{rechargeStatistics.remark,jdbcType=VARCHAR},
             </if>
-            <if test="operator != null">
-                #{operator,jdbcType=VARCHAR},
+            <if test="rechargeStatistics.operator != null">
+                #{rechargeStatistics.operator,jdbcType=VARCHAR},
             </if>
-            <if test="optTime != null">
-                #{optTime,jdbcType=TIMESTAMP},
+            <if test="rechargeStatistics.optTime != null">
+                #{rechargeStatistics.optTime,jdbcType=TIMESTAMP},
             </if>
         </trim>
     </insert>
@@ -108,6 +108,12 @@
         where id = #{user.id}
     </update>
 
+    <update id="updateSelectiveByOutTradeNo">
+        UPDATE t_express_account_recharge_record
+          set payStatus = #{rechargeStatistics.payStatus}
+        where outTradeNo = #{rechargeStatistics.outTradeNo} and payStatus = 0
+    </update>
+
     <select id="expressInfo" resultType="com.parksong.beans.express.ExpressApplets">
         select
             a.id, a.expcode expressCode, a.expId expressId, b.name expressName, a.shelfCode,