Human.func.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. *发短信
  4. * @param number $templateId
  5. * @param number $phone
  6. * @param string $vars
  7. * @return string
  8. */
  9. function send_sms($templateId=0,$phone=0,$vars='') {
  10. $url = 'http://www.sendcloud.net/smsapi/send';
  11. //'{"%name%":"欧桃珍"}'
  12. if(empty($templateId)||empty($phone)||empty($vars))
  13. return '';
  14. $param = array(
  15. 'smsUser' => 'smartcost',
  16. 'templateId' => $templateId,
  17. 'msgType' => '0',
  18. 'phone' => $phone,
  19. 'vars' => $vars
  20. );
  21. $sParamStr = "";
  22. ksort($param);
  23. foreach ($param as $sKey => $sValue) {
  24. $sParamStr .= $sKey . '=' . $sValue . '&';
  25. }
  26. $sParamStr = trim($sParamStr, '&');
  27. $smskey = 'kuGmqTt10n6vBXivhxXsAuG8aoCsQ1x6';
  28. $sSignature = md5($smskey."&".$sParamStr."&".$smskey);
  29. $param = array(
  30. 'smsUser' => 'smartcost',
  31. 'templateId' => $templateId,
  32. 'msgType' => '0',
  33. 'phone' => $phone,
  34. 'vars' => $vars,
  35. 'signature' => $sSignature
  36. );
  37. $data = http_build_query($param);
  38. $options = array(
  39. 'http' => array(
  40. 'method' => 'POST',
  41. 'header' => 'Content-Type:application/x-www-form-urlencoded',
  42. 'content' => $data
  43. ));
  44. $context = stream_context_create($options);
  45. $result = file_get_contents($url, FILE_TEXT, $context);
  46. return $result;
  47. }
  48. ?>