蛋蛋星球-制度模式
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.

преди 1 седмица
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package mob
  2. import (
  3. utils "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils"
  4. "errors"
  5. "fmt"
  6. "github.com/tidwall/gjson"
  7. )
  8. func MobSms(key, phone, templateCode string) error {
  9. where := make(map[string]interface{})
  10. send := ""
  11. var err error
  12. where = map[string]interface{}{
  13. "appkey": key,
  14. "zone": "86",
  15. "phone": phone,
  16. "templateCode": templateCode,
  17. }
  18. send, err = SmsMobApiSend(where)
  19. if err != nil {
  20. return err
  21. }
  22. status := gjson.Get(send, "status").Int()
  23. msg := gjson.Get(send, "error").String()
  24. if status == 471 {
  25. return errors.New("发送的ip不在白名单中")
  26. }
  27. if status == 406 {
  28. return errors.New("appkey不存在")
  29. }
  30. if status != 200 {
  31. return errors.New(msg)
  32. }
  33. return nil
  34. }
  35. func MobSMSCheck(key, phone, captcha string) (bool, error) {
  36. // mob 的短信验证
  37. // https://www.mob.com/wiki/detailed/?wiki=SMSSDK_for_yanzhengmafuwuduanxiaoyanjiekou&id=23
  38. url := "https://webapi.sms.mob.com/sms/verify"
  39. args := map[string]string{
  40. "phone": phone,
  41. "zone": "86",
  42. "code": captcha,
  43. }
  44. args["appkey"] = key
  45. // 发送请求
  46. respBody, err := utils.CurlPost(url, args, nil)
  47. if err != nil {
  48. fmt.Println(err)
  49. return false, err
  50. }
  51. code := gjson.GetBytes(respBody, "status").Int()
  52. if code == 468 {
  53. return false, errors.New("验证码错误")
  54. }
  55. if code != 200 {
  56. utils.FilePutContents("sms", string(respBody))
  57. return false, errors.New("验证码错误~")
  58. }
  59. return true, nil
  60. }
  61. func SmsMobApiSend(args map[string]interface{}) (string, error) {
  62. thisUrl := "https://webapi.sms.mob.com/sms/sendmsg"
  63. post, err := utils.CurlPost(thisUrl, args, nil)
  64. fmt.Println(string(post))
  65. fmt.Println(err)
  66. return string(post), err
  67. }