Browse Source

'微信接口'

Althars123 4 years ago
parent
commit
d6b161426a

+ 9 - 8
zzjs-admin/src/main/java/com/miaxis/app/controller/wechat/WxController.java

@@ -1,5 +1,6 @@
 package com.miaxis.app.controller.wechat;
 
+import com.alibaba.fastjson.JSONObject;
 import com.miaxis.common.aliyunOSS.AliyunConfig;
 import com.miaxis.common.aliyunOSS.AliyunUpload;
 import com.miaxis.common.constant.Constants;
@@ -54,17 +55,17 @@ public class WxController extends BaseController{
      */
     @GetMapping(value = "/openid")
     @ApiOperation("获取用户openid")
-    public Response<String> getInfo(
-            @ApiParam(name = "jscode", value = "jscode", required = true)
-            String jscode
-    ){
-        WxResult wxInfo = wxService.getWxInfo(appid, secret, jscode);
-        if (wxInfo.getErrcode() == 0){
-            return Response.success(wxInfo.getOpenid()) ;
+    public Response<String> getInfo(String jscode){
+        String result = wxService.getWxInfo(appid, secret, jscode,"authorization_code");
+        JSONObject jsonString = JSONObject.parseObject(result);
+        WxResult wxResult = JSONObject.toJavaObject(jsonString, WxResult.class);
+        if (wxResult.getErrcode() == 0){
+            return Response.success(wxResult.getOpenid()) ;
         }
         else{
-            return Response.error(500,wxInfo.getErrmsg());
+            return Response.error(500,wxResult.getErrmsg());
         }
+
     }
 
 

+ 5 - 5
zzjs-service/src/main/java/com/miaxis/feign/dto/WxResult.java

@@ -5,9 +5,9 @@ import lombok.Data;
 
 @Data
 public class WxResult {
-    private String openid;
-    private String session_key;
-    private String unionid;
-    private Integer errcode;
-    private String errmsg;
+     String openid;
+     String session_key;
+     String unionid;
+     Integer errcode;
+     String errmsg;
 }

+ 4 - 2
zzjs-service/src/main/java/com/miaxis/feign/service/IWxService.java

@@ -1,6 +1,7 @@
 package com.miaxis.feign.service;
 
 
+import com.alibaba.fastjson.JSONObject;
 import com.miaxis.common.config.FeignConfig;
 import com.miaxis.feign.dto.WxResult;
 import org.springframework.cloud.openfeign.FeignClient;
@@ -17,9 +18,10 @@ import org.springframework.web.bind.annotation.RequestParam;
 @Component
 public interface IWxService {
     @GetMapping(value = "/sns/jscode2session")
-    WxResult getWxInfo(
+    String getWxInfo(
             @RequestParam("appid") String appid,
             @RequestParam("secret") String secret,
-            @RequestParam("js_code") String jsCode);
+            @RequestParam("js_code") String jsCode,
+            @RequestParam("grant_type") String grantType);
 
 }