Browse Source

体积小

XMLWAN 2 years ago
parent
commit
bb7e2b6a88

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

@@ -65,6 +65,9 @@ func XcxApiControllersRegisterRouters() {
65 65
 	beego.Router("/xcx/api/mobile/getarticlistdetail", &XcxApiController{}, "Get:GetArticListDetail")
66 66
 
67 67
 	beego.Router("/xcx/api/mobile/getstoryscore", &XcxApiController{}, "Get:GetStoryScoreList")
68
+
69
+	//获取appid
70
+	beego.Router("/xcx/api/mobile/getappid", &XcxApiController{}, "Get:GetAppId")
68 71
 }
69 72
 
70 73
 type XcxApiController struct {
@@ -474,7 +477,8 @@ func (this *XcxApiController) GetLoginInfor() {
474 477
 }
475 478
 
476 479
 func (this *XcxApiController) GetPatientList() {
477
-	appid := "wx20b60369111b063a"
480
+	//appid := "wx20b60369111b063a"
481
+	appid := "wxcdf53b48b7df107e"
478 482
 	key := "Yz1HgsFX3yJvWPJSEdwJDA=="
479 483
 	strs := "uSevGQ5ShkiHjQuqz7s36SKZisVGA4fHH/dy+etg0W7ibVeidl6TyFS+kQZ6B9AI2T+1kOtKXeyveQR7q2TXJdu3fhKCFoLKVFzICNEvkiHMnchJ0T0OpRO3oT+icYq80+egvT+jMSgP7yi0cAgmiKaK/4QURD7+nvxRAj9drzz77sbeFt8KElb1LN/+Wn8dIoQzisxbON9G1VJYYtyBkQ=="
480 484
 	iv := "JgsbDhJ613uaAgAoBVh0Zw=="
@@ -1041,3 +1045,16 @@ func (this *XcxApiController) GetStoryScoreList() {
1041 1045
 		"total": total,
1042 1046
 	})
1043 1047
 }
1048
+
1049
+func (this *XcxApiController) GetAppId() {
1050
+
1051
+	var appid = "wxcdf53b48b7df107e"
1052
+	var secret = "94e944a69ad1d43ac447f5a8769ab801"
1053
+	var grant_type = "authorization_code"
1054
+	code := this.GetString("js_code")
1055
+
1056
+	openId, _ := service.SendWxAuthAPI(appid, secret, grant_type, code)
1057
+	this.ServeSuccessJSON(map[string]interface{}{
1058
+		"openId": openId,
1059
+	})
1060
+}

+ 1 - 1
routers/router.go View File

@@ -13,7 +13,7 @@ import (
13 13
 func init() {
14 14
 	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
15 15
 		// AllowAllOrigins:  true,
16
-		AllowOrigins: []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://localhost:9529", "http://localhost:9531", "http://xt.test.shengws.com", "http://new_mobile.test.sgjyun.com", "https://xt.test.shengws.com", "http://xt.test.sgjyun.com", "https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com", "https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com", "http://mobile.sgjyun.com", "http://mobile.kuyicloud.com", "http://xcx.sgjyun.com"},
16
+		AllowOrigins: []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://localhost:9529", "http://localhost:9531", "http://xt.test.shengws.com", "http://new_mobile.test.sgjyun.com", "https://xt.test.shengws.com", "http://xt.test.sgjyun.com", "https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com", "https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com", "http://mobile.sgjyun.com", "http://mobile.kuyicloud.com", "https://api.shengws.com", "http://xcx.sgjyun.com"},
17 17
 		//AllowOrigins:     []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://xt.test.shengws.com","https://xt.test.shengws.com", "http://xt.test.sgjyun.com","https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com","https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com","http://mobile.sgjyun.com","http://mobile.kuyicloud.com"},
18 18
 		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
19 19
 		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "X-XSRF-TOKEN", "Permission"},

+ 38 - 0
service/xcx_mobile_api_service.go View File

@@ -9,6 +9,7 @@ import (
9 9
 	"errors"
10 10
 	"fmt"
11 11
 	"github.com/jinzhu/gorm"
12
+	"net/http"
12 13
 	"time"
13 14
 )
14 15
 
@@ -632,3 +633,40 @@ func GetStoryScoreList(activityID int64, page int64, limit int64) (score []*mode
632 633
 	err = UserReadDB().Model(&score).Where("activity_id = ?", activityID).Count(&total).Offset(offset).Limit(limit).Preload("SybStory").Find(&score).Error
633 634
 	return score, total, err
634 635
 }
636
+
637
+//func GetOpenId(appid string,secret string,grant_type string,code string)(string, error)
638
+//
639
+//  var code2sessionURL = "https://xcx.kuyicloud.com/xcx/api/mobile/getappid?appid="
640
+//
641
+//  url := fmt.Sprintf(code2sessionURL, appID, appSecret, code)
642
+//  resp, err := http.DefaultClient.Get(url)
643
+//  if err != nil {
644
+//  return "", err
645
+//  }
646
+//  var wxMap map[string]string
647
+//  err = json.NewDecoder(resp.Body).Decode(&wxMap)
648
+//  if err != nil {
649
+//  return "", err
650
+//  }
651
+//  defer resp.Body.Close()
652
+//
653
+//  return wxMap["openid"], nil
654
+//}
655
+
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
658
+	var url = fmt.Sprintf(code2sessionURL, appID, appSecret, code)
659
+	fmt.Println("url233232323322323", url)
660
+	resp, err := http.DefaultClient.Get(url)
661
+	if err != nil {
662
+		return "", err
663
+	}
664
+	var wxMap map[string]string
665
+	err = json.NewDecoder(resp.Body).Decode(&wxMap)
666
+	if err != nil {
667
+		return "", err
668
+	}
669
+	defer resp.Body.Close()
670
+
671
+	return wxMap["openid"], nil
672
+}