优惠券订单及其他脚本

YPSM.class.php 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. //define("YP_SMS_KEY", "fbdb5f2ddae13c2f4a592348bfe52137");
  3. define("YP_SMS_KEY", "73a74eb72c42b765669acd8e94096b9f");
  4. define("YP_SMS_KEY_FAMLI",'995629e02beaaf47118b84ac19c4b5b9');
  5. define("YP_VOICE_URL", "http://voice.yunpian.com/v2/voice/send.json");
  6. define("YP_TPL_URL", "https://sms.yunpian.com/v2/sms/tpl_single_send.json");
  7. define("YP_TPL_MANY_URL", "https://sms.yunpian.com/v2/sms/tpl_batch_send.json");
  8. define("YP_TPL_ID", "2731830");
  9. define("RED_TPL_ID", "2741432");
  10. define("NEW_TPL_ID1", "2765270");
  11. define("NEW_TPL_ID2", "2765274");
  12. define("NEW_TPL_ID3", "2765282");
  13. class YPSMS{
  14. private static function init(){
  15. $ch = curl_init();
  16. /* 设置验证方式 */
  17. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8',
  18. 'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
  19. /* 设置返回结果为流 */
  20. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  21. /* 设置超时时间*/
  22. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  23. /* 设置通信方式 */
  24. curl_setopt($ch, CURLOPT_POST, 1);
  25. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  26. return $ch;
  27. }
  28. public static function sendSMS($phone, $money){
  29. $ch=self::init();
  30. $param = [
  31. 'apikey' => YP_SMS_KEY,
  32. 'mobile' => $phone,
  33. 'tpl_id' => YP_TPL_ID,
  34. 'tpl_value' =>('#code#').'='.$money
  35. ];
  36. $json_data = self::tpl_send($ch,$param);
  37. $array = json_decode($json_data,true);
  38. curl_close($ch);
  39. return $array;
  40. }
  41. #提醒红包到账,分享帮拆
  42. public static function sendRedHelp($phone, $money, $name){
  43. $ch=self::init();
  44. $param = [
  45. 'apikey' => YP_SMS_KEY,
  46. 'mobile' => $phone,
  47. 'tpl_id' => RED_TPL_ID,
  48. 'tpl_value' =>('#name#').'='.$name.'&'.('#money#').'='.$money
  49. ];
  50. $json_data = self::tpl_send($ch,$param);
  51. $array = json_decode($json_data,true);
  52. curl_close($ch);
  53. return $array;
  54. }
  55. # 提醒新手红包
  56. public static function sendNewRed($phone, $name, $flag=1,$money=22){
  57. $ch=self::init();
  58. $param = [
  59. 'apikey' => YP_SMS_KEY,
  60. 'mobile' => $phone,
  61. ];
  62. $param['tpl_value'] = '';
  63. if($flag==1){
  64. $param['tpl_id'] = NEW_TPL_ID1;
  65. }elseif($flag==3){
  66. $param['tpl_id'] = NEW_TPL_ID3;
  67. }
  68. $param['tpl_value'] = ('#name#').'='.$name.'&'.('#money#').'='.$money;
  69. $json_data = self::tpl_send($ch,$param);
  70. $array = json_decode($json_data,true);
  71. curl_close($ch);
  72. return $array;
  73. }
  74. # 超过三天未登录单独发
  75. public static function sendNewRed2($phone, $name='',$money=22){
  76. $ch=self::init();
  77. $param = [
  78. 'apikey' => YP_SMS_KEY,
  79. 'mobile' => $phone,
  80. ];
  81. $param['tpl_id'] = NEW_TPL_ID2;
  82. $param['tpl_value'] = ('#name#').'='.$name.'&'.('#money#').'='.$money;
  83. $json_data = self::tpl_send($ch,$param);
  84. $array = json_decode($json_data,true);
  85. curl_close($ch);
  86. return $array;
  87. }
  88. public static function sendVoiceCheck($phone,$code){
  89. $ch=self::init();
  90. $data=array('code'=>$code,'apikey'=>YP_SMS_KEY,'mobile'=>$phone);
  91. $json_data =self::voice_send($ch,$data);
  92. // $array = json_decode($json_data,true);
  93. // echo '<pre>';print_r($array);
  94. curl_close($ch);
  95. return $json_data;
  96. }
  97. private static function checkErr($result,$error) {
  98. if($result === false)
  99. {
  100. echo 'Curl error: ' . $error;
  101. }
  102. // else
  103. // {
  104. // echo '操作完成没有任何错误';
  105. // }
  106. }
  107. private static function send($ch,$data){
  108. curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/single_send.json');
  109. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  110. $result = curl_exec($ch);
  111. $error = curl_error($ch);
  112. self::checkErr($result,$error);
  113. return $result;
  114. }
  115. private static function voice_send($ch,$data){
  116. curl_setopt ($ch, CURLOPT_URL, YP_VOICE_URL);
  117. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  118. $result = curl_exec($ch);
  119. $error = curl_error($ch);
  120. self::checkErr($result,$error);
  121. return $result;
  122. }
  123. private static function tpl_send($ch,$data){
  124. curl_setopt ($ch, CURLOPT_URL, YP_TPL_URL);
  125. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  126. $result = curl_exec($ch);
  127. $error = curl_error($ch);
  128. self::checkErr($result,$error);
  129. return $result;
  130. }
  131. private static function tpl_many_send($ch,$data){
  132. curl_setopt ($ch, CURLOPT_URL, YP_TPL_MANY_URL);
  133. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  134. $result = curl_exec($ch);
  135. $error = curl_error($ch);
  136. self::checkErr($result,$error);
  137. return $result;
  138. }
  139. }