mymps.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. function Post($curlPost, $url)
  3. {
  4. $curl = curl_init();
  5. curl_setopt($curl, CURLOPT_URL, $url);
  6. curl_setopt($curl, CURLOPT_HEADER, false);
  7. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  8. curl_setopt($curl, CURLOPT_NOBODY, true);
  9. curl_setopt($curl, CURLOPT_POST, true);
  10. curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
  11. $return_str = curl_exec($curl);
  12. curl_close($curl);
  13. return $return_str;
  14. }
  15. function xml_to_array($xml)
  16. {
  17. $reg = '/<(\\w+)[^>]*>([\\x00-\\xFF]*)<\\/\\1>/';
  18. if (preg_match_all($reg, $xml, $matches)) {
  19. $count = count($matches[0]);
  20. for ($i = 0; $i < $count; $i++) {
  21. $subxml = $matches[2][$i];
  22. $key = $matches[1][$i];
  23. if (preg_match($reg, $subxml)) {
  24. $arr[$key] = xml_to_array($subxml);
  25. }
  26. else {
  27. $arr[$key] = $subxml;
  28. }
  29. }
  30. }
  31. return $arr;
  32. }
  33. function msend_sms($sms_user, $sms_pwd, $mobile, $content)
  34. {
  35. global $charset;
  36. $statusStr = array(0 => '短信发送成功', -1 => '参数不全', -2 => '服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!', 30 => '密码错误', 40 => '账号不存在', 41 => '余额不足', 42 => '帐户已过期', 43 => 'IP地址限制', 50 => '内容含有敏感词');
  37. $smsapi = 'http://api.smsbao.com/';
  38. $user = $sms_user;
  39. $pass = md5($sms_pwd);
  40. $content = rawurlencode($content);
  41. $phone = $mobile;
  42. $sendurl = $smsapi . 'sms?u=' . $user . '&p=' . $pass . '&m=' . $phone . '&c=' . $content;
  43. $result = file_get_contents($sendurl);
  44. $gets['SubmitResult']['code'] = $result;
  45. $gets['SubmitResult']['msg'] = $charset == 'gbk' ? iconv('UTF-8', 'GBK', $statusStr[$result]) : $statusStr[$result];
  46. return $gets;
  47. }
  48. function msend_regsms($sms_user, $sms_pwd, $mobile, $yzm, $sms_regtpl = '')
  49. {
  50. $content = str_replace('{code}', $yzm, $sms_regtpl);
  51. $content = str_replace('{mobile}', $mobile, $content);
  52. $content = $content ? $content : '您的验证码是' . $yzm . '请不要把验证码泄露给其他人。如非本人操作,可不用理会!';
  53. $status = msend_sms($sms_user, $sms_pwd, $mobile, $content);
  54. if ($status['SubmitResult']['code'] == 0) {
  55. }
  56. write_sms_sendrecord($mobile, $content, $status['SubmitResult']['msg'], 'smsbao');
  57. }
  58. function msend_pwdsms($sms_user, $sms_pwd, $mobile, $yzm, $sms_pwdtpl = '')
  59. {
  60. $content = str_replace('{code}', $yzm, $sms_pwdtpl);
  61. $content = str_replace('{mobile}', $mobile, $content);
  62. $content = $content ? $content : '您的手机号:' . $mobile . ',找回密码验证码:' . $yzm . ',请不要把验证码泄露给其他人。如非本人操作,可不用理会!';
  63. $status = msend_sms($sms_user, $sms_pwd, $mobile, $content);
  64. if ($status['SubmitResult']['code'] == 0) {
  65. }
  66. write_sms_sendrecord($mobile, $content, $status['SubmitResult']['msg'], 'smsbao');
  67. }
  68. ?>