Exemplo n.º 1
0
Arquivo: api.php Projeto: ybluesky/h2o
/**
* 短信发送
* @param array $tag 配置信息模板标识 ['default','test']
配置信息
[
	'alisms'	=>	[
		'default'	=>	[
			'appkey'			=>	'23268950', //密钥
			'secretKey'	=>	'09003ad8710387cfd0742c9b7fd6aab2', //密钥
			'tags'	=>	[
				'test'=>'750_737' //短信模板标识
			]
		]
	]
]
* @param string $m 多手机号 以逗号分隔
* @param array $data 替换变量
*/
function AliSmsSend($tag, $m, $data)
{
    $c = new \TopClient();
    $smsconf = \H2O::getAppConfigs('alisms');
    if (empty($smsconf)) {
        throw new \Exception('Ali SMS config params is error');
    } else {
        if (isset($smsconf[$tag[0]])) {
            $config = $smsconf[$tag[0]];
        } else {
            throw new \Exception('Ali SMS config params is error: ' . $tag[0]);
        }
    }
    $c->appkey = $config['appkey'];
    $c->secretKey = $config['secretKey'];
    $req = new \OpenSmsSendmsgRequest();
    $smrequest = new \SendMessageRequest();
    $em = explode(',', $m);
    $ids = explode('_', $config['tags'][$tag[1]]);
    $smrequest->template_id = $ids[0];
    //模板ID
    $smrequest->signature_id = $ids[1];
    //签名ID
    $smrequest->context = json_decode(json_encode($data));
    //模板变量替换
    foreach ($em as $v) {
        // $smrequest->external_id="demo";
        // $smrequest->mobile="18610638306,13520839197";
        $smrequest->mobile = $v;
        // $smrequest->device_limit="123";
        // $smrequest->session_limit="123";
        // $smrequest->device_limit_in_time="123";
        // $smrequest->mobile_limit="123";
        // $smrequest->session_limit_in_time="123";
        // $smrequest->mobile_limit_in_time="123";
        // $smrequest->session_id="demo";
        // $smrequest->domain="demo";
        // $smrequest->device_id="demo";
        $req->setSendMessageRequest(json_encode($smrequest));
        $resp = $c->execute($req);
        return $resp->result->successful;
    }
}
Exemplo n.º 2
0
 /**
  * Author: chenyifan
  * Des: -baichuan-
  *
  * @param array $config
  *
  * @return Sms
  */
 public static function baichuan($config = [])
 {
     $sms = new self();
     foreach ($config as $key => $value) {
         $sms->config[$key] = $value;
     }
     $sms->callback = function () use($sms) {
         date_default_timezone_set('Asia/Shanghai');
         $c = new \TopClient();
         $c->appkey = $sms->config['appkey'];
         $c->secretKey = $sms->config['secret'];
         $c->format = 'json';
         $req = new \OpenSmsSendmsgRequest();
         $send_message_request = new \SendMessageRequest();
         $send_message_request->template_id = $sms->config['template_id'];
         $send_message_request->signature_id = $sms->config['signature_id'];
         $send_message_request->mobile = $sms->mobile;
         $send_message_request->context = $sms->config['context'];
         $req->setSendMessageRequest(json_encode($send_message_request));
         $resp = $c->execute($req);
         $result = $resp->result;
         if ($result->successful == true) {
             return true;
         }
         return $result;
     };
     return $sms;
 }
Exemplo n.º 3
0
 function post($phone, $type, $password)
 {
     global $_G;
     if (!is_phone($phone)) {
         msg('手机号码不正确');
     }
     $this->init($type);
     include_once ROOT_PATH . 'top/baichuan/OpenSmsSendmsgRequest.php';
     $req = new OpenSmsSendmsgRequest();
     $arr['template_id'] = $this->tplid;
     $arr['signature_id'] = $this->signature_id;
     $arr['context'] = array('appName' => $_G['setting']['title'], 'code' => $password);
     $arr['external_id'] = 'change_password';
     $arr['mobile'] = $phone;
     $SendMessageRequest = json_encode($arr);
     $req->setSendMessageRequest($SendMessageRequest);
     $resp = $_G['TOP']->execute($req);
     top_check_error($resp, true);
     $rs = $resp->result;
     if (!$rs->successful) {
         $this->save_session('post_' . $type . '_' . $phone);
         if ($this->debug) {
             L('发送修改密码短信错误:' . $rs->message . ',手机号' . $phone . ',domain:' . $arr['domain']);
         }
         return $rs->message;
     } else {
         return true;
     }
 }