12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- /**
- *发短信
- * @param number $templateId
- * @param number $phone
- * @param string $vars
- * @return string
- */
- function send_sms($templateId=0,$phone=0,$vars='') {
- $url = 'http://www.sendcloud.net/smsapi/send';
- //'{"%name%":"欧桃珍"}'
- if(empty($templateId)||empty($phone)||empty($vars))
- return '';
-
- $param = array(
- 'smsUser' => 'smartcost',
- 'templateId' => $templateId,
- 'msgType' => '0',
- 'phone' => $phone,
- 'vars' => $vars
- );
-
- $sParamStr = "";
- ksort($param);
- foreach ($param as $sKey => $sValue) {
- $sParamStr .= $sKey . '=' . $sValue . '&';
- }
-
- $sParamStr = trim($sParamStr, '&');
- $smskey = 'kuGmqTt10n6vBXivhxXsAuG8aoCsQ1x6';
- $sSignature = md5($smskey."&".$sParamStr."&".$smskey);
-
- $param = array(
- 'smsUser' => 'smartcost',
- 'templateId' => $templateId,
- 'msgType' => '0',
- 'phone' => $phone,
- 'vars' => $vars,
- 'signature' => $sSignature
- );
-
- $data = http_build_query($param);
- $options = array(
- 'http' => array(
- 'method' => 'POST',
- 'header' => 'Content-Type:application/x-www-form-urlencoded',
- 'content' => $data
-
- ));
- $context = stream_context_create($options);
- $result = file_get_contents($url, FILE_TEXT, $context);
- return $result;
- }
-
- ?>
|