优惠券订单及其他脚本

SendMsg.class.php 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. class SendMsg
  3. {
  4. private static $url = 'http://ads.726p.com/api/Code/V1/sendCode';
  5. private static $urls = 'http://ads.726p.com/api/Code/V1/sendCodes';
  6. private static $secretKey = 'e2635363a2ddc4404fb8706a89420b0d';
  7. # 阿里云短信
  8. public static function AliSendMsg($params){
  9. if(!isset($params['mobile']) || !isset($params['SignName'])){
  10. return ['code'=>4003,'message'=>'参数有误'];
  11. }
  12. $param = array();
  13. $param['mobile'] = $params['mobile']; //必填
  14. $param['type'] = 1;
  15. $param['tpl_id'] = 'SMS_74745003';
  16. if( isset($params['tpl_id']) ){
  17. $param['tpl_id'] = $params['tpl_id']; //选填模板id
  18. }
  19. $param['aisle'] = 3; //阿里
  20. $content = array();
  21. $content['SignName'] = $params['SignName']; //必填
  22. $content['TemplateParam']['code'] = mt_rand(1000,9999); //验证码
  23. //自定义模板变量
  24. if(isset($params['extra']) && !empty($params['extra'])){
  25. $content['TemplateParam'] = $params['extra'];
  26. }
  27. $param['parameter'] = json_encode($content);
  28. $res = self::curl_post(self::$url, $param);
  29. return $res;
  30. }
  31. # 阿里云短信多条
  32. public static function AliSendMoreMsg($params){
  33. if(!isset($params['mobiles']) || !isset($params['SignName'])){
  34. return ['code'=>4003,'message'=>'参数有误'];
  35. }
  36. $param = array();
  37. $param['mobiles'] = $params['mobiles']; //必填
  38. $param['type'] = 1;
  39. $param['tpl_id'] = 'SMS_74745003';
  40. if( isset($params['tpl_id']) ){
  41. $param['tpl_id'] = $params['tpl_id']; //选填模板id
  42. }
  43. $param['aisle'] = 3; //阿里
  44. $content = array();
  45. $content['SignName'] = $params['SignName']; //必填
  46. $content['TemplateParam']['code'] = mt_rand(1000,9999); //验证码
  47. //自定义模板变量
  48. if(isset($params['extra']) && !empty($params['extra'])){
  49. $content['TemplateParam'] = $params['extra'];
  50. }
  51. $param['parameter'] = json_encode($content);
  52. $res = self::curl_post(self::$urls, $param);
  53. return $res;
  54. }
  55. # 天瑞云短信
  56. public static function TruiSendMsg($params){
  57. if(!isset($params['mobile']) || !isset($params['SignName'])){
  58. return ['code'=>4003,'message'=>'参数有误'];
  59. }
  60. $param = array();
  61. $param['mobile'] = $params['mobile']; //必填
  62. $param['type'] = 1;
  63. $param['tpl_id'] = '30233';
  64. if( isset($params['tpl_id']) ){
  65. $param['tpl_id'] = $params['tpl_id']; //选填模板id
  66. }
  67. $param['aisle'] = 2; //天瑞
  68. $content = array();
  69. $content['sign'] = '【'.$params['SignName'].'】'; //必填
  70. $content['content'] = mt_rand(1000,9999).'##3';
  71. //自定义模板变量
  72. if(isset($params['extra']) && !empty($params['extra'])){
  73. $content['content'] = implode('##',$params['extra']);
  74. }
  75. $param['parameter'] = json_encode($content);
  76. $res = self::curl_post(self::$url, $param);
  77. return $res;
  78. }
  79. # 云片短信
  80. public static function YpianSendMsg($params){
  81. if(!isset($params['mobile'])){
  82. return ['code'=>4003,'message'=>'参数有误'];
  83. }
  84. $param = array();
  85. $param['mobile'] = $params['mobile']; //必填
  86. $param['type'] = 1;
  87. $param['tpl_id'] = '2122814';
  88. if( isset($params['tpl_id']) ){
  89. $param['tpl_id'] = $params['tpl_id']; //选填模板id
  90. }
  91. $param['aisle'] = 1; //云片
  92. $content = array();
  93. $content['code'] = mt_rand(1000,9999);
  94. $content['minutes'] = 3;
  95. //自定义模板变量
  96. if(isset($params['extra'])){
  97. $content = $params['extra'];
  98. }
  99. $param['parameter'] = json_encode($content);
  100. $res = self::curl_post(self::$url, $param);
  101. return $res;
  102. }
  103. private static function curl_post($url, $param){
  104. $time=time();
  105. $sign = self::getSignature($param, $time, self::$secretKey);
  106. $param['sign'] = $sign;
  107. $param = http_build_query($param);
  108. //var_dump($param,$sign,$time);
  109. $header = array('Content-Type:application/x-www-form-urlencoded;charset=utf-8','sign:'.$sign,'time:'.$time,'appkey:de34as');
  110. $ch = curl_init();//初始化curl
  111. curl_setopt($ch, CURLOPT_URL,$url);
  112. curl_setopt($ch, CURLOPT_HEADER, 0);//
  113. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  114. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
  115. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//绕过ssl验证
  116. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  117. curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
  118. curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
  119. $data = curl_exec($ch);//运行curl
  120. curl_close($ch);
  121. return json_decode($data,true);
  122. }
  123. private static function getSignature($params, $time, $secretKey)
  124. {
  125. // 按数组键名 正序排序
  126. ksort($params);
  127. $tem = array();
  128. foreach ($params as $k => $v) {
  129. if ($k !== 'sign') {
  130. $tem[] = "$k=$v";
  131. }
  132. }
  133. if (empty($tem)) {
  134. $sk = 'time=' . $time . $secretKey;
  135. } else {
  136. $sk = implode('&', $tem) . '&time=' . $time . $secretKey;
  137. }
  138. return md5($sk);
  139. }
  140. }