第三方api接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.7 KiB

  1. package zhimeng
  2. import (
  3. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  4. "fmt"
  5. "sort"
  6. "strconv"
  7. "time"
  8. )
  9. var StatusSuc int = 1
  10. type ZM struct {
  11. AK string
  12. SK string
  13. SMS_AK string
  14. SMS_SK string
  15. }
  16. // 智盟接口, 可以调取京东, 拼多多等
  17. const ZM_HOST = "http://www.izhim.com/"
  18. var (
  19. ZM_BASE_URL = ZM_HOST + "?mod=api&act=%s&ctrl=%s"
  20. APP_KEY = "300000001"
  21. SECRET_KEY = "95c347002b2750dbd4b6a03bd4196c18"
  22. SMS_APP_KEY = "300000175"
  23. SMS_SECRET_KEY = "6cf1dcd1820a576ff2cbecbe00d31df2"
  24. )
  25. func Send(act, op string, args map[string]interface{}) ([]byte, error) {
  26. router := fmt.Sprintf(ZM_BASE_URL, act, op)
  27. // args["appkey"] = APP_KEY
  28. args["time"] = strconv.Itoa(int(time.Now().Unix()))
  29. args["sign"] = sign(args, args["secret_key"].(string))
  30. // b, _ := json.Marshal(args)
  31. // fmt.Println(string(b))
  32. return zhios_third_party_utils.CurlPost(router, args, nil)
  33. }
  34. // SMSend is 发送短信用的key 和签名
  35. func SMSend(act, op, key, secret string, args map[string]interface{}) ([]byte, error) {
  36. router := fmt.Sprintf(ZM_BASE_URL, act, op)
  37. args["appkey"] = key
  38. args["time"] = strconv.Itoa(int(time.Now().Unix()))
  39. args["sign"] = sign(args, secret)
  40. fmt.Println("====短信==", router, args)
  41. return zhios_third_party_utils.CurlPost(router, args, nil)
  42. }
  43. func sign(m map[string]interface{}, SK string) string {
  44. // key sort
  45. keys := make([]string, 0, len(m))
  46. for k := range m {
  47. keys = append(keys, k)
  48. }
  49. sort.Strings(keys)
  50. str := ""
  51. for _, k := range keys {
  52. str += k + zhios_third_party_utils.AnyToString(m[k])
  53. }
  54. // merge string
  55. str = SK + str + SK + "方诺科技"
  56. return zhios_third_party_utils.Md5(str)
  57. }