优惠券小程序

YPSMS.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Support;
  3. class YPSMS
  4. {
  5. const YP_TPL_URL = 'https://sms.yunpian.com/v2/sms/tpl_single_send.json';
  6. private static function init()
  7. {
  8. $ch = curl_init();
  9. /* 设置验证方式 */
  10. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8',
  11. 'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
  12. /* 设置返回结果为流 */
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  14. /* 设置超时时间*/
  15. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  16. /* 设置通信方式 */
  17. curl_setopt($ch, CURLOPT_POST, 1);
  18. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  19. return $ch;
  20. }
  21. private static function send($ch, $data)
  22. {
  23. curl_setopt ($ch, CURLOPT_URL, self::YP_TPL_URL);
  24. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  25. $result = curl_exec($ch);
  26. return $result;
  27. }
  28. public static function warn_check_rule($phone, $param, $ruleType)
  29. {
  30. $ch = self::init();
  31. $sms_key = '995629e02beaaf47118b84ac19c4b5b9';
  32. switch ($ruleType) {
  33. case 'oudaa':
  34. $tpl_id = '5235852';
  35. break;
  36. case 'oudpa':
  37. $tpl_id = '5235856';
  38. break;
  39. case 'nuhaa':
  40. $tpl_id = '5235858';
  41. break;
  42. case 'numpa':
  43. $tpl_id = '5235866';
  44. break;
  45. case 'auaaa':
  46. $tpl_id = '5276092';
  47. break;
  48. default:
  49. return false;
  50. }
  51. $tpl_value =
  52. urlencode("#group#")."=".urlencode($param['group'])
  53. ."&".
  54. urlencode("#corp#")."=".urlencode($param['corp'])
  55. ."&".
  56. urlencode("#user#")."=".urlencode($param['user'])
  57. ."&".
  58. urlencode("#num#")."=".urlencode($param['num']);
  59. $data = [
  60. 'apikey' => $sms_key,
  61. 'mobile' => $phone,
  62. 'tpl_id' => $tpl_id,
  63. 'tpl_value' => $tpl_value,
  64. ];
  65. $json_data = self::send($ch, $data);
  66. $array = json_decode($json_data,true);
  67. curl_close($ch);
  68. return $array;
  69. }
  70. }