yidong.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package yidong
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/rdlucklib/rdluck_tools/http"
  7. "hongze/hongze_open_api/models/tables/open_api_user"
  8. "hongze/hongze_open_api/utils"
  9. "strconv"
  10. "strings"
  11. )
  12. // GetSign 获取签名
  13. func GetSign(activityIdYiDong string, timeInt int) string {
  14. signStr := fmt.Sprintf(`activity_id=%stime=%s`, activityIdYiDong, strconv.Itoa(timeInt))
  15. signStr += utils.YIDONG_HONGZE_KEY
  16. fmt.Print(signStr)
  17. return strings.ToUpper(utils.MD5(signStr))
  18. }
  19. func CheckAppidAndIp(appid, ip string) (err error) {
  20. if appid == "" {
  21. err = errors.New("缺少appid参数")
  22. return
  23. }
  24. openApiUserInfo, tmpErr := open_api_user.GetByAppid(appid)
  25. if tmpErr != nil {
  26. if tmpErr.Error() == utils.ErrNoRow() {
  27. err = errors.New("appid异常,请联系管理员")
  28. } else {
  29. err = errors.New("系统异常,请联系管理员")
  30. }
  31. return
  32. }
  33. if openApiUserInfo == nil {
  34. err = errors.New("系统异常,请联系管理员")
  35. return
  36. }
  37. //如果有ip限制,那么就添加ip
  38. //if openApiUserInfo.Ip != "" {
  39. // if !strings.Contains(openApiUserInfo.Ip, ip) {
  40. // err = errors.New(fmt.Sprintf("无权限访问该接口,ip:%v,请联系管理员", ip))
  41. // return
  42. // }
  43. //}
  44. return
  45. }
  46. // Response 结构体表示整个响应
  47. type CrmApiUserResponse struct {
  48. Code int `json:"code"`
  49. Msg string `json:"msg"`
  50. Data *CrmApiUserData `json:"data"`
  51. }
  52. type CrmApiCodeResponse struct {
  53. Code int `json:"code" comment:"返回码"`
  54. }
  55. // Data 结构体表示数据部分
  56. type CrmApiUserData struct {
  57. ContactInfo *CrmApiUserContactInfo `json:"contactInfo"`
  58. }
  59. // ContactInfo 结构体表示联系人信息
  60. type CrmApiUserContactInfo struct {
  61. Status int `json:"status"`
  62. }
  63. // GetClptCrmWorkerRule 根据手机号,获取策略平台用户对应的权限
  64. func GetClptCrmWorkerRule(mobile string) (statusResp int, err error) {
  65. crmUrl := utils.CLPT_CRM_URL + `worker/api/getWorkerRule?phone=%s&token=a2db0ab2ca6367741cab37f34d602987`
  66. crmUrl = fmt.Sprintf(crmUrl, mobile)
  67. body, err := http.Get(crmUrl)
  68. //utils.FileLog.Info("lt result:%s", string(body))
  69. if err != nil {
  70. return
  71. }
  72. // 尝试解析成功的响应
  73. var responseCode CrmApiCodeResponse
  74. err = json.Unmarshal(body, &responseCode)
  75. if err != nil {
  76. fmt.Println("JSON解析失败:", err)
  77. return
  78. }
  79. //如果状态码不等于1 ,就把直接返回
  80. if responseCode.Code != 1 {
  81. return
  82. }
  83. item := new(CrmApiUserResponse)
  84. err = json.Unmarshal(body, &item)
  85. if err != nil {
  86. return
  87. }
  88. //codeResp := item.Code
  89. //if codeResp != 1 {
  90. // return
  91. //}
  92. statusResp = item.Data.ContactInfo.Status
  93. return
  94. }