merchantSend($phone,$merchantid); }else{ $smsconfig = M("sms_config")->find(); $msl = $smsconfig["accesscode"]; $code = rand(100000, 999999); //定义验证码 session('identifying_codes', $code, 300); //把验证码存到session $res = $this->sendSms($phone, $code, $msl); return json_decode(json_encode($res), true); } } public function SendRecharge($phone, $data){ $msl = 'SMS_128880321'; $this->sendSms1($phone, $msl, $data); } function sendSms1($phone, $msl, $arr) { require_once "/SignatureHelper.php"; $params = array(); // *** 需用户填写部分 *** // fixme 必填: 请参阅 https://ak-console.aliyun.com/ 取得您的AK信息 $accessKeyId = C('accessKeyId'); $accessKeySecret = C('accessKeySecret'); // fixme 必填: 短信接收号码 $params["PhoneNumbers"] = $phone; // fixme 必填: 短信签名,应严格按"签名名称"填写,请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/sign $params["SignName"] = "互支付"; // fixme 必填: 短信模板Code,应严格按"模板CODE"填写, 请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/template $params["TemplateCode"] = $msl; // fixme 可选: 设置模板参数, 假如模板中存在变量需要替换则为必填项 $params['TemplateParam'] = $arr; // fixme 可选: 设置发送短信流水号 $params['OutId'] = "12345"; // fixme 可选: 上行短信扩展码, 扩展码字段控制在7位或以下,无特殊需求用户请忽略此字段 $params['SmsUpExtendCode'] = "1234567"; // *** 需用户填写部分结束, 以下代码若无必要无需更改 *** if (!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) { $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE); } // 初始化SignatureHelper实例用于设置参数,签名以及发送请求 $helper = new \SignatureHelper(); // 此处可能会抛出异常,注意catch $content = $helper->request( $accessKeyId, $accessKeySecret, "dysmsapi.aliyuncs.com", array_merge($params, array( "RegionId" => "cn-hangzhou", "Action" => "SendSms", "Version" => "2017-05-25", )) // fixme 选填: 启用https // ,true ); return $content; } function sendSms($phone, $code, $Msl) { require_once "./SignatureHelper.php"; $params = array(); // *** 需用户填写部分 *** // fixme 必填: 请参阅 https://ak-console.aliyun.com/ 取得您的AK信息 //$accessKeyId = C('accessKeyId'); //$accessKeySecret = C('accessKeySecret'); $smsconfig = M("sms_config")->find(); $accessKeyId = $smsconfig["accesskeyid"]; $accessKeySecret = $smsconfig["accesskeysecret"]; // fixme 必填: 短信接收号码 $params["PhoneNumbers"] = $phone; // fixme 必填: 短信签名,应严格按"签名名称"填写,请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/sign $params["SignName"] = $smsconfig["accessname"]; // fixme 必填: 短信模板Code,应严格按"模板CODE"填写, 请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/template $params["TemplateCode"] = $Msl ? $Msl : "SMS_128635518"; // fixme 可选: 设置模板参数, 假如模板中存在变量需要替换则为必填项 $params['TemplateParam'] = Array( "code" => $code ); // fixme 可选: 设置发送短信流水号 $params['OutId'] = "12345"; // fixme 可选: 上行短信扩展码, 扩展码字段控制在7位或以下,无特殊需求用户请忽略此字段 $params['SmsUpExtendCode'] = "1234567"; // *** 需用户填写部分结束, 以下代码若无必要无需更改 *** if (!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) { $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE); } // 初始化SignatureHelper实例用于设置参数,签名以及发送请求 $helper = new \SignatureHelper(); // 此处可能会抛出异常,注意catch $content = $helper->request( $accessKeyId, $accessKeySecret, "dysmsapi.aliyuncs.com", array_merge($params, array( "RegionId" => "cn-hangzhou", "Action" => "SendSms", "Version" => "2017-05-25", )) // fixme 选填: 启用https // ,true ); return $content; } // 商户自己的验证码 public function merchantSend($phone,$merchantid){ $AlDaYu = M('retail_smsset')->where(array('merchantid'=>$merchantid))->find(); $cansend = true; if(empty($AlDaYu)){ // 商户未设置 $cansend = false; }else if($AlDaYu['status']==2){ // 商户关闭短信 $cansend = false; } if(!$cansend){ // 系统的短信验证码 $msl = 'SMS_134329267'; $code = rand(100000, 999999); //定义验证码 session('identifying_codes', $code, 300); //把验证码存到session $res = $this->sendSms($phone, $code, $msl); return json_decode(json_encode($res), true); }else{ // 商户自己的短信验证码 $code = rand(100000, 999999); //定义验证码 session('identifying_codes', $code, 300); //把验证码存到session $res = $this->merchantSendSms($phone, $code, $AlDaYu); file_put_contents('sms3.txt',json_encode($res)); return json_decode(json_encode($res), true); } } // 商户验证码 public function merchantSendSms($phone, $code, $AlDaYu){ require_once "/SignatureHelper.php"; $params = array(); // *** 需用户填写部分 *** // fixme 必填: 请参阅 https://ak-console.aliyun.com/ 取得您的AK信息 $accessKeyId = $AlDaYu['accesskeyid']; $accessKeySecret =$AlDaYu['accesskeysecret']; // fixme 必填: 短信接收号码 $params["PhoneNumbers"] = $phone; // fixme 必填: 短信签名,应严格按"签名名称"填写,请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/sign $params["SignName"] = $AlDaYu['signname']; // fixme 必填: 短信模板Code,应严格按"模板CODE"填写, 请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/template $params["TemplateCode"] = $AlDaYu['verifitemplatecode']; // fixme 可选: 设置模板参数, 假如模板中存在变量需要替换则为必填项 $params['TemplateParam'] = Array( "code" => $code ); // fixme 可选: 设置发送短信流水号 $params['OutId'] = "12345"; // fixme 可选: 上行短信扩展码, 扩展码字段控制在7位或以下,无特殊需求用户请忽略此字段 $params['SmsUpExtendCode'] = "1234567"; // *** 需用户填写部分结束, 以下代码若无必要无需更改 *** if (!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) { $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE); } // 初始化SignatureHelper实例用于设置参数,签名以及发送请求 $helper = new \SignatureHelper(); // 此处可能会抛出异常,注意catch $content = $helper->request( $accessKeyId, $accessKeySecret, "dysmsapi.aliyuncs.com", array_merge($params, array( "RegionId" => "cn-hangzhou", "Action" => "SendSms", "Version" => "2017-05-25", )) ); return $content; } // 测试发送验证码 public function textSms(){ $phone = I('post.phone'); $merchantid = I('post.merchantid'); $res=$this->Send($phone,$merchantid); return $res; } }