From 5196a1d1e00ced009a2d4e8ea0aa5f3bb7cefe33 Mon Sep 17 00:00:00 2001
From: EricsHu <hrr145632>
Date: 星期一, 10 四月 2023 15:56:37 +0800
Subject: [PATCH] 小程序登陆绑定

---
 src/main/java/com/qxueyou/scc/wx/service/impl/WechatService.java |   47 ++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/qxueyou/scc/wx/service/impl/WechatService.java b/src/main/java/com/qxueyou/scc/wx/service/impl/WechatService.java
index 5f98963..3400b95 100644
--- a/src/main/java/com/qxueyou/scc/wx/service/impl/WechatService.java
+++ b/src/main/java/com/qxueyou/scc/wx/service/impl/WechatService.java
@@ -1,8 +1,11 @@
 package com.qxueyou.scc.wx.service.impl;
 
+import cn.hutool.http.HttpUtil;
 import com.alibaba.druid.util.HttpClientUtils;
+import com.alibaba.druid.util.StringUtils;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.qxueyou.scc.base.model.Result;
 import com.qxueyou.scc.base.service.ICacheService;
 import com.qxueyou.scc.teach.student.model.StuStudent;
 import com.qxueyou.scc.wx.service.IWechatService;
@@ -67,16 +70,50 @@
     }
 
     @Override
-    public String getNumber(String number) {
-        String requestUrl = "https://api.weixin.qq.com/wxa/business/getuserphonenumber";
+    public Result getNumber(String tonken, String number) {
+        JSONObject jsonCode = new JSONObject();
+
+        jsonCode.put("code",number);
+
+
+        String resPhone = HttpClientUtil.doPostUrl("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + tonken, jsonCode);
+
+        if(StringUtils.isEmpty(resPhone) || !resPhone.contains("phone_info") ||  !resPhone.contains("phoneNumber")){
+            return new Result(false,"寰俊瀹樻柟淇敼浜嗗皬绋嬪簭鑾峰彇鐢ㄦ埛鎵嬫満鍙风爜鐩稿叧鎺ュ彛锛�");
+        }
+        JSONObject resPhoneInfo = JSON.parseObject(resPhone);
+        JSONObject phoneInfo=resPhoneInfo.getJSONObject("phone_info");
+        System.out.println(resPhoneInfo);
+        System.out.println(phoneInfo);
+        String phoneNumber = phoneInfo.get("phoneNumber").toString();
+
+        return new Result(true,"鑾峰彇鎵嬫満鍙锋垚鍔�",phoneNumber);
+//        String requestUrl = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token="+tonken+jsonObject.toJSONString();
+
+//        Map<String, String> requestUrlParam = new HashMap<>();
+
+
+
+//        requestUrlParam.put("code", number);
+
+//        JSONObject s =JSON.parseObject(HttpClientUtil.doPost(requestUrl));
+
+//        return s;
+    }
+
+    @Override
+    public JSONObject gettoken(String appid, String secret) {
+        String requestUrl = "https://api.weixin.qq.com/cgi-bin/token";
 
         Map<String, String> requestUrlParam = new HashMap<>();
 
-        requestUrlParam.put("access_token", "access_token");
+        requestUrlParam.put("grant_type", "client_credential");
 
-        requestUrlParam.put("code", number);
+        requestUrlParam.put("appid", appid);
 
-        String s = HttpClientUtil.doPost(requestUrl, requestUrlParam);
+        requestUrlParam.put("secret", secret);
+
+        JSONObject s = JSON.parseObject(HttpClientUtil.doGet(requestUrl, requestUrlParam));
 
         return s;
     }

--
Gitblit v1.8.0