123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package yidong
- import (
- "encoding/json"
- "errors"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/http"
- "hongze/hongze_open_api/models/tables/open_api_user"
- "hongze/hongze_open_api/utils"
- "strconv"
- "strings"
- )
- // GetSign 获取签名
- func GetSign(activityIdYiDong string, timeInt int) string {
- signStr := fmt.Sprintf(`activity_id=%stime=%s`, activityIdYiDong, strconv.Itoa(timeInt))
- signStr += utils.YIDONG_HONGZE_KEY
- fmt.Print(signStr)
- return strings.ToUpper(utils.MD5(signStr))
- }
- func CheckAppidAndIp(appid, ip string) (err error) {
- if appid == "" {
- err = errors.New("缺少appid参数")
- return
- }
- openApiUserInfo, tmpErr := open_api_user.GetByAppid(appid)
- if tmpErr != nil {
- if tmpErr.Error() == utils.ErrNoRow() {
- err = errors.New("appid异常,请联系管理员")
- } else {
- err = errors.New("系统异常,请联系管理员")
- }
- return
- }
- if openApiUserInfo == nil {
- err = errors.New("系统异常,请联系管理员")
- return
- }
- //如果有ip限制,那么就添加ip
- //if openApiUserInfo.Ip != "" {
- // if !strings.Contains(openApiUserInfo.Ip, ip) {
- // err = errors.New(fmt.Sprintf("无权限访问该接口,ip:%v,请联系管理员", ip))
- // return
- // }
- //}
- return
- }
- // Response 结构体表示整个响应
- type CrmApiUserResponse struct {
- Code int `json:"code"`
- Msg string `json:"msg"`
- Data *CrmApiUserData `json:"data"`
- }
- type CrmApiCodeResponse struct {
- Code int `json:"code" comment:"返回码"`
- }
- // Data 结构体表示数据部分
- type CrmApiUserData struct {
- ContactInfo *CrmApiUserContactInfo `json:"contactInfo"`
- }
- // ContactInfo 结构体表示联系人信息
- type CrmApiUserContactInfo struct {
- Status int `json:"status"`
- }
- // GetClptCrmWorkerRule 根据手机号,获取策略平台用户对应的权限
- func GetClptCrmWorkerRule(mobile string) (statusResp int, err error) {
- crmUrl := utils.CLPT_CRM_URL + `worker/api/getWorkerRule?phone=%s&token=a2db0ab2ca6367741cab37f34d602987`
- crmUrl = fmt.Sprintf(crmUrl, mobile)
- body, err := http.Get(crmUrl)
- //utils.FileLog.Info("lt result:%s", string(body))
- if err != nil {
- return
- }
- // 尝试解析成功的响应
- var responseCode CrmApiCodeResponse
- err = json.Unmarshal(body, &responseCode)
- if err != nil {
- fmt.Println("JSON解析失败:", err)
- return
- }
- //如果状态码不等于1 ,就把直接返回
- if responseCode.Code != 1 {
- return
- }
- item := new(CrmApiUserResponse)
- err = json.Unmarshal(body, &item)
- if err != nil {
- return
- }
- //codeResp := item.Code
- //if codeResp != 1 {
- // return
- //}
- statusResp = item.Data.ContactInfo.Status
- return
- }
|