Send.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. *
  4. * User: anyluck
  5. * Date: 2020/6/9
  6. * Time: 17:36
  7. */
  8. namespace app\web\model;
  9. class Send
  10. {
  11. // 第三方 短信验证码
  12. private static $url="http://v.juhe.cn/sms/send";
  13. private static $key="bb0c0c29147b4629aa2db6faba90afc4";
  14. // 登录
  15. public static function login_code($mobile,$code)
  16. {
  17. $params["mobile"]=$mobile;
  18. $params["tpl_id"]="215598";
  19. $params["tpl_value"]=urlencode("#code#=".$code."&#company#=聚合数据");
  20. $params["key"]=self::$key;
  21. $params["dtype"]="json";
  22. $paramstring = http_build_query($params);
  23. $content = self::juheCurl(self::$url, $paramstring);
  24. $result = json_decode($content, true);
  25. if ($result["error_code"]==0){
  26. return true;
  27. }else{
  28. return false;
  29. }
  30. }
  31. /**
  32. * 请求接口返回内容
  33. * @param string $url [请求的URL地址]
  34. * @param string $params [请求的参数]
  35. * @param int $ipost [是否采用POST形式]
  36. * @return string
  37. */
  38. public static function juheCurl($url, $params = false, $ispost = 0)
  39. {
  40. $httpInfo = array();
  41. $ch = curl_init();
  42. curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  43. curl_setopt($ch, CURLOPT_USERAGENT, 'JuheData');
  44. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
  45. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  46. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  47. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  48. if ($ispost) {
  49. curl_setopt($ch, CURLOPT_POST, true);
  50. curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  51. curl_setopt($ch, CURLOPT_URL, $url);
  52. } else {
  53. if ($params) {
  54. curl_setopt($ch, CURLOPT_URL, $url.'?'.$params);
  55. } else {
  56. curl_setopt($ch, CURLOPT_URL, $url);
  57. }
  58. }
  59. $response = curl_exec($ch);
  60. if ($response === FALSE) {
  61. //echo "cURL Error: " . curl_error($ch);
  62. return false;
  63. }
  64. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  65. $httpInfo = array_merge($httpInfo, curl_getinfo($ch));
  66. curl_close($ch);
  67. return $response;
  68. }
  69. }