yidong.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. // Data 结构体表示数据部分
  53. type CrmApiUserData struct {
  54. ContactInfo *CrmApiUserContactInfo `json:"contactInfo"`
  55. }
  56. // ContactInfo 结构体表示联系人信息
  57. type CrmApiUserContactInfo struct {
  58. Status int `json:"status"`
  59. }
  60. // GetClptCrmWorkerRule 根据手机号,获取策略平台用户对应的权限
  61. func GetClptCrmWorkerRule(mobile string) (statusResp int, err error) {
  62. crmUrl := utils.CLPT_CRM_URL + `worker/api/getWorkerRule?phone=%s&token=a2db0ab2ca6367741cab37f34d602987`
  63. crmUrl = fmt.Sprintf(crmUrl, mobile)
  64. body, err := http.Get(crmUrl)
  65. //utils.FileLog.Info("lt result:%s", string(body))
  66. if err != nil {
  67. return
  68. }
  69. item := new(CrmApiUserResponse)
  70. err = json.Unmarshal(body, &item)
  71. if err != nil {
  72. return
  73. }
  74. //如果状态码不等于1 ,就把直接返回
  75. codeResp := item.Code
  76. if codeResp != 1 {
  77. return
  78. }
  79. statusResp = item.Data.ContactInfo.Status
  80. return
  81. }