1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- 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"`
- }
- // 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
- }
- item := new(CrmApiUserResponse)
- err = json.Unmarshal(body, &item)
- if err != nil {
- return
- }
- //如果状态码不等于1 ,就把直接返回
- codeResp := item.Code
- if codeResp != 1 {
- return
- }
- statusResp = item.Data.ContactInfo.Status
- return
- }
|