From d83e4be3fe4e5a3c52d70ab36d64584e966c1800 Mon Sep 17 00:00:00 2001
From: Administrator <zhubaomin>
Date: 星期一, 17 六月 2024 09:02:09 +0800
Subject: [PATCH] 2024-06-17 朱宝民 优化微信支付代码

---
 pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java |  141 +++++++++++++++++++++++++++++++++--------------
 1 files changed, 99 insertions(+), 42 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java
index af54665..196f207 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java
@@ -13,6 +13,7 @@
 import com.dy.pipIrrGlobal.pojoSe.SeCodeVerify;
 import com.dy.pipIrrGlobal.pojoSe.SeOpenId;
 import com.dy.pipIrrGlobal.voSe.VoClient;
+import com.dy.pipIrrGlobal.voSe.VoClientWechat;
 import com.dy.pipIrrSell.client.dto.CodeVerifyDTO;
 import com.dy.pipIrrSell.result.SellResultCode;
 import com.dy.pipIrrSell.sms.AliyunSmsSv;
@@ -353,6 +354,55 @@
     }
 
     /**
+     * 鏍规嵁鏉慖D鑾峰彇12浣嶈鏀垮尯鍒�
+     * @param villageId
+     * @return
+     */
+    @Operation(summary = "鏍规嵁鏉慖D鑾峰彇12浣嶈鏀垮尯鍒�", description = "鏍规嵁鏉慖D鑾峰彇12浣嶈鏀垮尯鍒�")
+    @ApiResponses(value = {
+            @ApiResponse(
+                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
+                    description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
+                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
+                            schema = @Schema(implementation = Boolean.class))}
+            )
+    })
+    @GetMapping(path = "district")
+    @SsoAop()
+    public BaseResponse<Boolean> getDistrictNum(@RequestParam("villageId") @NotNull(message = "鏉戠紪鍙蜂笉鑳戒负绌�") Long villageId){
+        /**
+         * 鑾峰彇5绾ц鏀垮尯鍒掍俊鎭�
+         */
+        Map map_districts = Optional.ofNullable(clientSv.getDistrictsByVillageId(villageId)).orElse(new HashMap());
+        if(map_districts.size() <= 0) {
+            return BaseResponseUtils.buildFail("鍖哄垝淇℃伅鏈夎");
+        }
+
+        String provinceNum = map_districts.get("provinceNum").toString();
+        String cityNum = map_districts.get("cityNum").toString();
+        String countyNum = map_districts.get("countyNum").toString();
+        String townNum = map_districts.get("townNum").toString();
+        String villageNum = map_districts.get("villageNum").toString();
+
+        // 鐢熸垚12浣�5绾ц鏀垮尯鍒掔紪鐮佷覆鍙婂悕绉颁覆
+        Long districtNum = Long.parseLong(provinceNum + cityNum + countyNum + townNum + villageNum);
+        //鑾峰彇椤圭洰缂栫爜
+        String projectNo = clientSv.getItemValue("projectNo");
+        //杞负int
+        Integer projectNo1 = Integer.valueOf(projectNo);
+        //杞负16杩涘埗
+//        String projectNo2 = Integer.toHexString(projectNo1);
+//        log.info(projectNo2);
+        String projectNo3 = String.format("%02x", projectNo1);
+        log.info(projectNo3);
+
+        Map map = new HashMap();
+        map.put("districtNum", districtNum);
+        map.put("projectNo",projectNo3);
+        return BaseResponseUtils.buildSuccess(map);
+    }
+
+    /**
      * 鍙戦�侀獙璇佺爜
      * @param phoneNumber
      * @return
@@ -463,6 +513,7 @@
         String sessionKey = job.getString("session_key");
 
         Long clientId = clientSv.getClientIdByPhone(phoneNumber);
+        String SessionId = "";
         if(clientId != null) {
             // 娣诲姞寰俊鐢ㄦ埛璐︽埛璁板綍
             SeOpenId seOpenId = new SeOpenId();
@@ -470,7 +521,11 @@
             seOpenId.setOpenId(openid);
             seOpenId.setSessionKey(sessionKey);
             seOpenId.setCreateTime(new Date());
-            Long SessionId = clientSv.addOpenId(seOpenId);
+            //Long SessionId = clientSv.addOpenId(seOpenId);
+            Long rec = clientSv.addOpenId(seOpenId);
+            if(rec != null) {
+                SessionId = String.valueOf(rec);
+            }
             return BaseResponseUtils.buildSuccess(SessionId);
 
         } else {
@@ -479,51 +534,53 @@
     }
 
     /**
-     * 鏍规嵁鏉慖D鑾峰彇12浣嶈鏀垮尯鍒�
-     * @param villageId
+     * 鑾峰彇鍐滄埛鍩烘湰淇℃伅锛屽皬绋嬪簭棣栭〉浣跨敤
+     * @param sessionId
      * @return
      */
-    @Operation(summary = "鏍规嵁鏉慖D鑾峰彇12浣嶈鏀垮尯鍒�", description = "鏍规嵁鏉慖D鑾峰彇12浣嶈鏀垮尯鍒�")
-    @ApiResponses(value = {
-            @ApiResponse(
-                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
-                    description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
-                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
-                            schema = @Schema(implementation = Boolean.class))}
-            )
-    })
-    @GetMapping(path = "district")
+    @GetMapping(path = "/simple_info")
     @SsoAop()
-    public BaseResponse<Boolean> getDistrictNum(@RequestParam("villageId") @NotNull(message = "鏉戠紪鍙蜂笉鑳戒负绌�") Long villageId){
-        /**
-         * 鑾峰彇5绾ц鏀垮尯鍒掍俊鎭�
-         */
-        Map map_districts = Optional.ofNullable(clientSv.getDistrictsByVillageId(villageId)).orElse(new HashMap());
-        if(map_districts.size() <= 0) {
-            return BaseResponseUtils.buildFail("鍖哄垝淇℃伅鏈夎");
+    public BaseResponse<VoClientWechat> getSimpleClientInfo(@RequestParam Long sessionId){
+        try {
+            VoClientWechat res = clientSv.getSimpleClientInfo(sessionId, null);
+            return BaseResponseUtils.buildSuccess(res);
+        } catch (Exception e) {
+            log.error("鏌ヨ鍐滄埛寮傚父", e);
+            return BaseResponseUtils.buildException(e.getMessage()) ;
+        }
+    }
+
+    /**
+     * 鐧诲綍鍑瘉鐧诲綍
+     * @param code 涓存椂鐧诲綍鍑瘉
+     * @return
+     */
+    @GetMapping(path = "/code_login")
+    @SsoAop()
+    public BaseResponse<VoClientWechat> codeLogin(@RequestParam String code) throws IOException {
+
+        // 鐧诲綍鍑瘉鏍¢獙
+        Map<String, Object> queryParams = new HashMap<>();
+        queryParams.put("appid", appid);
+        queryParams.put("secret", secret);
+        queryParams.put("js_code", code);
+        queryParams.put("grant_type", grantType);
+        Map<String, String> headerParams = new HashMap<>();
+        JSONObject job = restTemplateUtil.get(loginUrl, queryParams, headerParams);
+
+        String openId = job.getString("openid");
+        if(openId == null) {
+            return BaseResponseUtils.buildFail(SellResultCode.LOGIN_FAIL.getMessage());
         }
 
-        String provinceNum = map_districts.get("provinceNum").toString();
-        String cityNum = map_districts.get("cityNum").toString();
-        String countyNum = map_districts.get("countyNum").toString();
-        String townNum = map_districts.get("townNum").toString();
-        String villageNum = map_districts.get("villageNum").toString();
-
-        // 鐢熸垚12浣�5绾ц鏀垮尯鍒掔紪鐮佷覆鍙婂悕绉颁覆
-        Long districtNum = Long.parseLong(provinceNum + cityNum + countyNum + townNum + villageNum);
-        //鑾峰彇椤圭洰缂栫爜
-        String projectNo = clientSv.getItemValue("projectNo");
-        //杞负int
-        Integer projectNo1 = Integer.valueOf(projectNo);
-        //杞负16杩涘埗
-//        String projectNo2 = Integer.toHexString(projectNo1);
-//        log.info(projectNo2);
-        String projectNo3 = String.format("%02x", projectNo1);
-        log.info(projectNo3);
-
-        Map map = new HashMap();
-        map.put("districtNum", districtNum);
-        map.put("projectNo",projectNo3);
-        return BaseResponseUtils.buildSuccess(map);
+        try {
+            VoClientWechat res = clientSv.getSimpleClientInfo(null, openId);
+            return BaseResponseUtils.buildSuccess(res);
+        } catch (Exception e) {
+            log.error("鏌ヨ鍐滄埛寮傚父", e);
+            return BaseResponseUtils.buildException(e.getMessage()) ;
+        }
     }
+
+
 }

--
Gitblit v1.8.0