Procházet zdrojové kódy

fix:卡卷获取与领取方法

duxin před 3 roky
rodič
revize
1c060e7b05
4 změnil soubory, kde provedl 63 přidání a 0 odebrání
  1. 7 0
      config/config.go
  2. 1 0
      etc/config.yaml
  3. 1 0
      etc/push.json
  4. 54 0
      handler/activity/lotteryService.go

+ 7 - 0
config/config.go

@@ -43,6 +43,12 @@ var (
 	PushConfig *pushConfig
 )
 
+type LotteryReceiveReq struct {
+	UserName     string `json:"userName"`
+	UserId       string `json:"userId"`
+	AppId        string `json:"appId"`
+	LotteryIdArr string `json:"lotteryIdArr"`
+}
 type pushConfig struct {
 	Webdomain    string `json:"webdomain"`
 	Weixinrpc    string `json:"weixinrpc"`
@@ -60,6 +66,7 @@ type pushConfig struct {
 	DelayedTime int    `json:"delayedTime"`
 	Subvip      string `json:"subvip"`
 	Points      string `json:"points"`
+	ActivityUrl string `json:"activityUrl"`
 }
 
 //var Config *config

+ 1 - 0
etc/config.yaml

@@ -1,6 +1,7 @@
 # 代理网关服务配置
 webport: :8076
 appid: 10000
+receivingLocation: 0
 # 基础服务ETCD配置
 etcd:
   # 基础服务

+ 1 - 0
etc/push.json

@@ -29,6 +29,7 @@
       "color": "#686868"
     }
   },
+  "activityUrl": "",
   "testId": "o7Y1g0Rz_1JmNep3lnIU4lfjeooI",
   "delayedTime": 5,
   "subvip": "天超级订阅",

+ 54 - 0
handler/activity/lotteryService.go

@@ -0,0 +1,54 @@
+package activity
+
+import (
+	"app.yhyue.com/moapp/message/config"
+	"encoding/json"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	url2 "net/url"
+	"strconv"
+)
+
+//ActivityLottery 获取活动下的奖券 receivingLocation 奖券形式0落地页 1付款页 999全部 3 我的奖券 productCode 活动code
+func ActivityLottery(userId, appId, receivingLocation, productCode string) (map[string]interface{}, error) {
+	//url := config.PushConfig.ActivityUrl + "/activityLottery?userId=" + userId + "&appId=" + appId + "&activityId=" + activityId + "&receivingLocation=" + receivingLocation + "&productCode=" + productCode
+	url := config.PushConfig.ActivityUrl + "/activityLottery?userId=" + userId + "&appId=" + appId + "&receivingLocation=" + receivingLocation + "&productCode=" + productCode
+
+	fmt.Println(url)
+	request, err := http.NewRequest("GET", url, nil)
+	client := http.Client{}
+	resp, err := client.Do(request)
+	if err != nil {
+		return nil, err
+	}
+	defer resp.Body.Close()
+	var info map[string]interface{}
+	result, _ := ioutil.ReadAll(resp.Body)
+	if err := json.Unmarshal(result, &info); err == nil {
+		fmt.Println("==============json str 转map=======================", info)
+	}
+
+	return info, nil
+}
+
+//LotteryReceive 奖卷领取 LotteryIdArr 奖券id 支持多个逗号拼接
+func LotteryReceive(lotteryRep config.LotteryReceiveReq) (int, string) {
+	userNameStr := url2.PathEscape(lotteryRep.UserName)
+	url := config.PushConfig.ActivityUrl + "/lotteryReceive?userName=" + userNameStr + "&userId=" + lotteryRep.UserId + "&appId=" + lotteryRep.AppId + "&lotteryIdArr=" + lotteryRep.LotteryIdArr
+	fmt.Println(url)
+	request, err := http.NewRequest("POST", url, nil)
+	client := http.Client{}
+	resp, err := client.Do(request)
+	if err != nil {
+		return 0, "奖券领取失败"
+	}
+	defer resp.Body.Close()
+	var info map[string]interface{}
+	result, _ := ioutil.ReadAll(resp.Body)
+	if err := json.Unmarshal([]byte(result), &info); err == nil {
+		fmt.Println("==============json str 转map=======================", info)
+	}
+	codeInt, err := strconv.Atoi(fmt.Sprint(info["Code"]))
+	return codeInt, fmt.Sprint(info["Message"])
+}