瀏覽代碼

体积小

XMLWAN 3 年之前
父節點
當前提交
bb7e2b6a88
共有 3 個文件被更改,包括 57 次插入2 次删除
  1. 18 1
      controllers/xcx_mobile_api_controller.go/xcx_api_controller.go
  2. 1 1
      routers/router.go
  3. 38 0
      service/xcx_mobile_api_service.go

+ 18 - 1
controllers/xcx_mobile_api_controller.go/xcx_api_controller.go 查看文件

65
 	beego.Router("/xcx/api/mobile/getarticlistdetail", &XcxApiController{}, "Get:GetArticListDetail")
65
 	beego.Router("/xcx/api/mobile/getarticlistdetail", &XcxApiController{}, "Get:GetArticListDetail")
66
 
66
 
67
 	beego.Router("/xcx/api/mobile/getstoryscore", &XcxApiController{}, "Get:GetStoryScoreList")
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
 type XcxApiController struct {
73
 type XcxApiController struct {
474
 }
477
 }
475
 
478
 
476
 func (this *XcxApiController) GetPatientList() {
479
 func (this *XcxApiController) GetPatientList() {
477
-	appid := "wx20b60369111b063a"
480
+	//appid := "wx20b60369111b063a"
481
+	appid := "wxcdf53b48b7df107e"
478
 	key := "Yz1HgsFX3yJvWPJSEdwJDA=="
482
 	key := "Yz1HgsFX3yJvWPJSEdwJDA=="
479
 	strs := "uSevGQ5ShkiHjQuqz7s36SKZisVGA4fHH/dy+etg0W7ibVeidl6TyFS+kQZ6B9AI2T+1kOtKXeyveQR7q2TXJdu3fhKCFoLKVFzICNEvkiHMnchJ0T0OpRO3oT+icYq80+egvT+jMSgP7yi0cAgmiKaK/4QURD7+nvxRAj9drzz77sbeFt8KElb1LN/+Wn8dIoQzisxbON9G1VJYYtyBkQ=="
483
 	strs := "uSevGQ5ShkiHjQuqz7s36SKZisVGA4fHH/dy+etg0W7ibVeidl6TyFS+kQZ6B9AI2T+1kOtKXeyveQR7q2TXJdu3fhKCFoLKVFzICNEvkiHMnchJ0T0OpRO3oT+icYq80+egvT+jMSgP7yi0cAgmiKaK/4QURD7+nvxRAj9drzz77sbeFt8KElb1LN/+Wn8dIoQzisxbON9G1VJYYtyBkQ=="
480
 	iv := "JgsbDhJ613uaAgAoBVh0Zw=="
484
 	iv := "JgsbDhJ613uaAgAoBVh0Zw=="
1041
 		"total": total,
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 查看文件

13
 func init() {
13
 func init() {
14
 	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
14
 	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
15
 		// AllowAllOrigins:  true,
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
 		//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"},
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
 		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
18
 		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
19
 		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "X-XSRF-TOKEN", "Permission"},
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 查看文件

9
 	"errors"
9
 	"errors"
10
 	"fmt"
10
 	"fmt"
11
 	"github.com/jinzhu/gorm"
11
 	"github.com/jinzhu/gorm"
12
+	"net/http"
12
 	"time"
13
 	"time"
13
 )
14
 )
14
 
15
 
632
 	err = UserReadDB().Model(&score).Where("activity_id = ?", activityID).Count(&total).Offset(offset).Limit(limit).Preload("SybStory").Find(&score).Error
633
 	err = UserReadDB().Model(&score).Where("activity_id = ?", activityID).Count(&total).Offset(offset).Limit(limit).Preload("SybStory").Find(&score).Error
633
 	return score, total, err
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
+}