From 73b750200f25df08aa64124da49e7461f9de6653 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期五, 13 十二月 2024 15:09:49 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/NTTravel

---
 UserNTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/WeChatUtil.java |   91 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 90 insertions(+), 1 deletions(-)

diff --git a/UserNTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/WeChatUtil.java b/UserNTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/WeChatUtil.java
index 1961a68..65056ae 100644
--- a/UserNTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/WeChatUtil.java
+++ b/UserNTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/WeChatUtil.java
@@ -2,16 +2,33 @@
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.stylefeng.guns.core.util.ToolUtil;
+import com.stylefeng.guns.modular.api.UserInfoController;
+import com.stylefeng.guns.modular.system.util.HttpClientUtil;
+import com.stylefeng.guns.modular.system.util.RedisUtil;
+import com.stylefeng.guns.modular.system.util.UUIDUtil;
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.http.entity.ContentType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.*;
+import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.stereotype.Component;
 import org.springframework.web.client.RestTemplate;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
 
 /**
  * 微信工具类
@@ -27,6 +44,7 @@
 
     @Autowired
     private RestTemplate restTemplate;
+
 
 
     /**
@@ -112,9 +130,80 @@
      * @return
      */
     public String getAccessToken(){
-        String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx0e72f86394831b34&secret=930f857abc74f7bb5cbd89e1544c5669";
+        String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxe91f1af7638aa5dd&secret=a787e1a462715604e0c9528b6d8960d1";
         String backData = restTemplate.getForObject(url, String.class);
         String accessToken = JSONObject.parseObject(backData).getString("access_token");
         return accessToken;
     }
+
+    public String getUrlLink(String path, String query) throws Exception{
+        String wxAppletsAccessToken = getAccessToken();
+        String url = "https://api.weixin.qq.com/wxa/generate_urllink?access_token=" + wxAppletsAccessToken;
+        Map<String, Object> param = new HashMap<>();
+        param.put("expire_type", 1);
+        param.put("expire_interval", 1);
+        param.put("path", path);
+        param.put("query", query);
+        param.put("env_version", "trial");
+        HttpHeaders httpHeaders = new HttpHeaders();
+        MediaType type=MediaType.parseMediaType("application/json;charset=UTF-8");
+        httpHeaders.setContentType(type);
+        HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(param, httpHeaders);
+        ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
+        String body1 = exchange.getBody();
+        return body1;
+    }
+
+    public String getPhone(String code) throws Exception{
+        String wxAppletsAccessToken = getAccessToken();
+        String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + wxAppletsAccessToken;
+        Map<String, Object> param = new HashMap<>();
+        param.put("code",code);
+        HttpHeaders httpHeaders = new HttpHeaders();
+        MediaType type=MediaType.parseMediaType("application/json;charset=UTF-8");
+        httpHeaders.setContentType(type);
+        HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(param, httpHeaders);
+        ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
+        String body1 = exchange.getBody();
+//        String body1 ="{\"errcode\":0,\"errmsg\":\"ok\",\"phone_info\":{\"phoneNumber\":\"15708179461\",\"purePhoneNumber\":\"15708179461\",\"countryCode\":\"86\",\"watermark\":{\"timestamp\":1720420413,\"appid\":\"wxc89ecab90d24edd8\"}}}";
+
+        JSONObject jsonObject = JSON.parseObject(body1);
+        // 从JSON对象中获取phone_info子对象
+        JSONObject phoneInfo = jsonObject.getJSONObject("phone_info");
+        // 从phone_info中获取phoneNumber
+        String phoneNumber = phoneInfo.getString("phoneNumber");
+        System.out.println("Phone Number: " + phoneNumber);
+
+
+        return phoneNumber;
+    }
+
+    
+    @Autowired
+    private UserInfoController userInfoController;
+    public String rid(String path, String query) throws Exception{
+        // 获取access_token
+        String accessToken = getAccessToken();
+        // 替换CREATE_CODE_URL
+        String url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token="+accessToken;
+        // 发送请求
+        String stringApiResult = null;
+        try {
+            HashMap<String, String> map = new HashMap<>();
+            map.put("path", path+"?driverId=979");
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_JSON);
+            HttpEntity requestEntity = new HttpEntity(map, headers);
+            ResponseEntity<byte[]> rep = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class);
+            byte[] bytes = rep.getBody();
+            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
+            MultipartFile file = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), byteArrayInputStream);
+            ResultUtil resultUtil = userInfoController.uploadImg(file, null, null);
+            StringBuilder sb = new StringBuilder(stringApiResult);
+            stringApiResult = sb.toString();
+        } catch (Exception e) {
+        }
+        return stringApiResult;
+    }
+
 }

--
Gitblit v1.7.1