|
@@ -5,6 +5,7 @@ import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"io/ioutil"
|
|
|
+ "log"
|
|
|
"net/http"
|
|
|
url2 "net/url"
|
|
|
"strconv"
|
|
@@ -15,40 +16,47 @@ func ActivityLottery(userId, appId, receivingLocation, productCode string) (map[
|
|
|
//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)
|
|
|
+ log.Println(url)
|
|
|
request, err := http.NewRequest("GET", url, nil)
|
|
|
- client := http.Client{}
|
|
|
- resp, err := client.Do(request)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
+ client := http.Client{}
|
|
|
+ resp, err1 := client.Do(request)
|
|
|
+ if err1 != nil {
|
|
|
+ return nil, err1
|
|
|
+ }
|
|
|
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
|
|
|
+ err = json.Unmarshal(result, &info)
|
|
|
+ fmt.Println("==============json str 转map=======================", info)
|
|
|
+ return info, err
|
|
|
}
|
|
|
|
|
|
//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)
|
|
|
+ log.Println(url)
|
|
|
request, err := http.NewRequest("POST", url, nil)
|
|
|
- client := http.Client{}
|
|
|
- resp, err := client.Do(request)
|
|
|
if err != nil {
|
|
|
+ return 0, err.Error()
|
|
|
+ }
|
|
|
+ client := http.Client{}
|
|
|
+ resp, err1 := client.Do(request)
|
|
|
+ if err1 != 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 {
|
|
|
+ if err = json.Unmarshal(result, &info); err == nil {
|
|
|
fmt.Println("==============json str 转map=======================", info)
|
|
|
}
|
|
|
- codeInt, err := strconv.Atoi(fmt.Sprint(info["Code"]))
|
|
|
+ codeInt, err2 := strconv.Atoi(fmt.Sprint(info["Code"]))
|
|
|
+ if err2 != nil {
|
|
|
+ return 0, err2.Error()
|
|
|
+ }
|
|
|
return codeInt, fmt.Sprint(info["Message"])
|
|
|
}
|