lotteryService.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package activity
  2. import (
  3. "app.yhyue.com/moapp/message/config"
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "net/http"
  8. url2 "net/url"
  9. "strconv"
  10. )
  11. //ActivityLottery 获取活动下的奖券 receivingLocation 奖券形式0落地页 1付款页 999全部 3 我的奖券 productCode 活动code
  12. func ActivityLottery(userId, appId, receivingLocation, productCode string) (map[string]interface{}, error) {
  13. //url := config.PushConfig.ActivityUrl + "/activityLottery?userId=" + userId + "&appId=" + appId + "&activityId=" + activityId + "&receivingLocation=" + receivingLocation + "&productCode=" + productCode
  14. url := config.PushConfig.ActivityUrl + "/activityLottery?userId=" + userId + "&appId=" + appId + "&receivingLocation=" + receivingLocation + "&productCode=" + productCode
  15. fmt.Println(url)
  16. request, err := http.NewRequest("GET", url, nil)
  17. client := http.Client{}
  18. resp, err := client.Do(request)
  19. if err != nil {
  20. return nil, err
  21. }
  22. defer resp.Body.Close()
  23. var info map[string]interface{}
  24. result, _ := ioutil.ReadAll(resp.Body)
  25. if err := json.Unmarshal(result, &info); err == nil {
  26. fmt.Println("==============json str 转map=======================", info)
  27. }
  28. return info, nil
  29. }
  30. //LotteryReceive 奖卷领取 LotteryIdArr 奖券id 支持多个逗号拼接
  31. func LotteryReceive(lotteryRep config.LotteryReceiveReq) (int, string) {
  32. userNameStr := url2.PathEscape(lotteryRep.UserName)
  33. url := config.PushConfig.ActivityUrl + "/lotteryReceive?userName=" + userNameStr + "&userId=" + lotteryRep.UserId + "&appId=" + lotteryRep.AppId + "&lotteryIdArr=" + lotteryRep.LotteryIdArr
  34. fmt.Println(url)
  35. request, err := http.NewRequest("POST", url, nil)
  36. client := http.Client{}
  37. resp, err := client.Do(request)
  38. if err != nil {
  39. return 0, "奖券领取失败"
  40. }
  41. defer resp.Body.Close()
  42. var info map[string]interface{}
  43. result, _ := ioutil.ReadAll(resp.Body)
  44. if err := json.Unmarshal([]byte(result), &info); err == nil {
  45. fmt.Println("==============json str 转map=======================", info)
  46. }
  47. codeInt, err := strconv.Atoi(fmt.Sprint(info["Code"]))
  48. return codeInt, fmt.Sprint(info["Message"])
  49. }