Browse Source

体积小

XMLWAN 3 years ago
parent
commit
0d4d083fd6

+ 3 - 1
controllers/xcx_mobile_api_controller.go/xcx_api_controller.go View File

1054
 	code := this.GetString("js_code")
1054
 	code := this.GetString("js_code")
1055
 
1055
 
1056
 	openId, _ := service.SendWxAuthAPI(appid, secret, grant_type, code)
1056
 	openId, _ := service.SendWxAuthAPI(appid, secret, grant_type, code)
1057
+	session_key, _ := service.SendWxAuthAPIOne(appid, secret, grant_type, code)
1057
 	this.ServeSuccessJSON(map[string]interface{}{
1058
 	this.ServeSuccessJSON(map[string]interface{}{
1058
-		"openId": openId,
1059
+		"openId":      openId,
1060
+		"session_key": session_key,
1059
 	})
1061
 	})
1060
 }
1062
 }

+ 19 - 1
service/xcx_mobile_api_service.go View File

654
 //}
654
 //}
655
 
655
 
656
 func SendWxAuthAPI(appID string, appSecret string, grant_type string, code string) (string, error) {
656
 func SendWxAuthAPI(appID string, appSecret string, grant_type string, code string) (string, error) {
657
-	var code2sessionURL = "https://xcx.kuyicloud.com/xcx/api/mobile/getappid?appid=" + appID + "&secret=" + appSecret + "&js_code=" + code + "&grant_type=" + grant_type
657
+	var code2sessionURL = "https://api.weixin.qq.com/sns/jscode2session?appid=" + appID + "&secret=" + appSecret + "&js_code=" + code + "&grant_type=" + grant_type
658
 	var url = fmt.Sprintf(code2sessionURL, appID, appSecret, code)
658
 	var url = fmt.Sprintf(code2sessionURL, appID, appSecret, code)
659
 	fmt.Println("url233232323322323", url)
659
 	fmt.Println("url233232323322323", url)
660
 	resp, err := http.DefaultClient.Get(url)
660
 	resp, err := http.DefaultClient.Get(url)
670
 
670
 
671
 	return wxMap["openid"], nil
671
 	return wxMap["openid"], nil
672
 }
672
 }
673
+
674
+func SendWxAuthAPIOne(appID string, appSecret string, grant_type string, code string) (string, error) {
675
+	var code2sessionURL = "https://api.weixin.qq.com/sns/jscode2session?appid=" + appID + "&secret=" + appSecret + "&js_code=" + code + "&grant_type=" + grant_type
676
+	var url = fmt.Sprintf(code2sessionURL, appID, appSecret, code)
677
+	fmt.Println("url233232323322323", url)
678
+	resp, err := http.DefaultClient.Get(url)
679
+	if err != nil {
680
+		return "", err
681
+	}
682
+	var wxMap map[string]string
683
+	err = json.NewDecoder(resp.Body).Decode(&wxMap)
684
+	if err != nil {
685
+		return "", err
686
+	}
687
+	defer resp.Body.Close()
688
+
689
+	return wxMap["session_key"], nil
690
+}