附近小店
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.
 
 
 

71 line
1.7 KiB

  1. package zhimeng
  2. import (
  3. "applet/app/utils"
  4. "applet/app/utils/logx"
  5. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/sms"
  6. "encoding/json"
  7. "xorm.io/xorm"
  8. )
  9. // 查询数量
  10. func SmsNum(engine *xorm.Engine, dbName, smsType, appKey, appSecret string) (int, error) {
  11. if smsType == "1" { //新的
  12. num := sms.SmsNumGetSmsNum(engine, "putong", dbName)
  13. return num, nil
  14. }
  15. params := map[string]interface{}{
  16. "appkey": appKey,
  17. "secret_key": appSecret,
  18. }
  19. resp, err := Send("send_msg", "msg_num", params)
  20. if err != nil {
  21. return 0, logx.Warn(err)
  22. }
  23. var tmp struct {
  24. Msg string `json:"msg"`
  25. Success int `json:"success"`
  26. Data struct {
  27. Count string `json:"count"`
  28. } `json:"data"`
  29. }
  30. if err = json.Unmarshal(resp, &tmp); err != nil {
  31. return 0, logx.Warn("[resp]: " + string(resp) + ", [err]:" + err.Error())
  32. }
  33. return utils.StrToInt(tmp.Data.Count), nil
  34. }
  35. func SmsToSend(engine *xorm.Engine, dbName, smsType, appKey, appSecret, content, phone string) (int, error) {
  36. if smsType == "1" { //新的
  37. args := map[string]interface{}{
  38. "mobile": phone,
  39. "content": content,
  40. "sms_type": "putong",
  41. "uid": dbName,
  42. }
  43. err := sms.SmsSend(engine, args)
  44. if err != nil {
  45. return 0, err
  46. }
  47. return 1, nil
  48. }
  49. params := map[string]interface{}{
  50. "appkey": appKey,
  51. "secret_key": appSecret,
  52. "mobile": phone,
  53. "content": content,
  54. }
  55. resp, err := Send("send_msg", "msg_doing", params)
  56. if err != nil {
  57. return 0, logx.Warn(err)
  58. }
  59. var tmp struct {
  60. Msg string `json:"msg"`
  61. Success int `json:"success"`
  62. }
  63. if err = json.Unmarshal(resp, &tmp); err != nil {
  64. return 0, logx.Warn("[resp]: " + string(resp) + ", [err]:" + err.Error())
  65. }
  66. return tmp.Success, nil
  67. }