Açıklama Yok

YPSMS.php 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. use App\libs\sms;
  3. define("YP_SMS_KEY_1", "fbdb5f2ddae13c2f4a592348bfe52137");
  4. //define('YP_SMS_YHQ', '73a74eb72c42b765669acd8e94096b9f');
  5. //define("YP_SMS_KEY_FAMLI",'995629e02beaaf47118b84ac19c4b5b9');
  6. //define("YP_VOICE_URL", "http://voice.yunpian.com/v2/voice/send.json");
  7. define("YP_TPL_URL_1", "https://sms.yunpian.com/v2/sms/tpl_single_send.json");
  8. //define("YP_TPL_ID", "2122814");
  9. class YPSMS{
  10. private static $order_tpl = [
  11. 1 => '3210114', //新订单审核提醒管理员
  12. //2 => '3210120', //新订单提醒仓管
  13. 2 => '3211800', //新订单提醒仓管
  14. 3 => '3210134', //订单发货提醒销售
  15. 4 => '3210146', //订单审核通过提醒销售
  16. 5 => '3210312', //订单审核驳回提醒销售
  17. 6 => '3391172', //redis预占库存异常报警
  18. ];
  19. private static function init(){
  20. $ch = curl_init();
  21. /* 设置验证方式 */
  22. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8',
  23. 'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
  24. /* 设置返回结果为流 */
  25. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  26. /* 设置超时时间*/
  27. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  28. /* 设置通信方式 */
  29. curl_setopt($ch, CURLOPT_POST, 1);
  30. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  31. return $ch;
  32. }
  33. public static function sendMsg($phone,$type,$order_id = null, $send_date = null){
  34. $tpl = self::$order_tpl;
  35. $tpl_id = $tpl[$type];
  36. $ch=self::init();
  37. //$data=array('tpl_id' => $tpl_id,'text'=>$text,'apikey'=>YP_SMS_KEY,'mobile'=>$phone);
  38. $data = [
  39. 'apikey' => YP_SMS_KEY_1,
  40. 'mobile' => $phone,
  41. 'tpl_id' => $tpl_id,
  42. ];
  43. if( in_array($type, [3,5]) ){
  44. $data['tpl_value'] = ('#order_id#').'='.$order_id;
  45. }elseif( $type == 2){
  46. $data['tpl_value'] = ('#order_id#').'='.$order_id.'&'. ('#send_date#').'='.urldecode($send_date);
  47. }
  48. $json_data = self::tpl_send($ch,$data);
  49. //print_r($json_data); ******************************maybe影响验证码发出
  50. $array = json_decode($json_data,true);
  51. // echo '<pre>';print_r($array);
  52. curl_close($ch);
  53. return $array;
  54. }
  55. //预占库存报警
  56. public static function sendSkuWnum($phone, $note = null){
  57. $tpl = self::$order_tpl;
  58. $tpl_id = $tpl[6];
  59. $ch=self::init();
  60. $data = [
  61. 'apikey' => YP_SMS_KEY_1,
  62. 'mobile' => $phone,
  63. 'tpl_id' => $tpl_id,
  64. ];
  65. $data['tpl_value'] = ('#note#').'='.$note;
  66. $json_data = self::tpl_send($ch,$data);
  67. $array = json_decode($json_data,true);
  68. curl_close($ch);
  69. return $array;
  70. }
  71. public static function sendSMS($phone,$text){
  72. $ch=self::init();
  73. // $data = array('tpl_id' => YP_TPL_ID, 'tpl_value' => ('#code#').'='.urlencode($code), 'apikey' => YP_SMS_KEY, 'mobile' => $phone);
  74. // $json_data = self::tpl_send($ch,$data);
  75. // $array = json_decode($json_data,true);
  76. // echo '<pre>';print_r($array);
  77. $data=array('tpl_id' => YP_TPL_ID,'text'=>$text,'apikey'=>YP_SMS_KEY_1,'mobile'=>$phone);
  78. $json_data = self::send($ch,$data);
  79. //print_r($json_data); ******************************maybe影响验证码发出
  80. $array = json_decode($json_data,true);
  81. // echo '<pre>';print_r($array);
  82. curl_close($ch);
  83. return $array;
  84. }
  85. public static function sendRedSMS($phone,$text,$id){
  86. $ch=self::init();
  87. $data=array('tpl_id' => $id,'text'=>$text,'apikey'=>YP_SMS_YHQ,'mobile'=>$phone);
  88. $json_data = self::send($ch,$data);
  89. curl_close($ch);
  90. return $json_data;
  91. }
  92. public static function sendVoiceCheck($phone,$code){
  93. $ch=self::init();
  94. $data=array('code'=>$code,'apikey'=>YP_SMS_KEY_1,'mobile'=>$phone);
  95. $json_data =self::voice_send($ch,$data);
  96. // $array = json_decode($json_data,true);
  97. // echo '<pre>';print_r($array);
  98. curl_close($ch);
  99. return $json_data;
  100. }
  101. private static function checkErr($result,$error) {
  102. if($result === false)
  103. {
  104. echo 'Curl error: ' . $error;
  105. }
  106. // else
  107. // {
  108. // echo '操作完成没有任何错误';
  109. // }
  110. }
  111. private static function send($ch,$data){
  112. curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/single_send.json');
  113. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  114. $result = curl_exec($ch);
  115. $error = curl_error($ch);
  116. self::checkErr($result,$error);
  117. return $result;
  118. }
  119. private static function voice_send($ch,$data){
  120. curl_setopt ($ch, CURLOPT_URL, YP_VOICE_URL);
  121. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  122. $result = curl_exec($ch);
  123. $error = curl_error($ch);
  124. self::checkErr($result,$error);
  125. return $result;
  126. }
  127. private static function tpl_send($ch,$data){
  128. curl_setopt ($ch, CURLOPT_URL, YP_TPL_URL_1);
  129. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  130. $result = curl_exec($ch);
  131. $error = curl_error($ch);
  132. self::checkErr($result,$error);
  133. return $result;
  134. }
  135. }
  136. // YPSMS::init();
  137. //$code=100;
  138. //$minutes=3;
  139. // YPSMS::sendSMS('13613665865','【钱多多随手记】您的验证码是' . $code . ',有效期为' . $minutes . '分钟,请尽快验证。');
  140. // YPSMS::sendVoiceCheck('13613665865','123456');