首页
关于
Search
1
Fastadmin 美化后台样式
310,896 阅读
2
关于破解移动宽带光猫 型号: GS3101 超级管理员密码
26,922 阅读
3
给Thinkphp3用上composer
19,965 阅读
4
Wallpaper完美壁纸修复天气bug(无需申请API)
19,758 阅读
5
PECL无法安装时手动编译安装PHP扩展
19,611 阅读
Linux
Mysql
PHP
Nginx
归档
Android
Python
IOS
浴室沉思
C++
CCF CSP认证
Windows
C#
前端
登录
Search
标签搜索
php
git
Windows
wkhtmltopdf
短信
defense
API
Google Photos
python
wkhtmltoimage
网页快照
linux
ssr
https
mail
sms
小程序
封装
ComoBox
拼多多
Guooo
累计撰写
126
篇文章
累计收到
81
条评论
首页
栏目
Linux
Mysql
PHP
Nginx
归档
Android
Python
IOS
浴室沉思
C++
CCF CSP认证
Windows
C#
前端
页面
关于
搜索到
1
篇与
的结果
2019-01-14
互亿短信调用模板 php
调用方法//调用方法 $code = mt_rand(1000, 9999); $sms = new Huyisms(); // 发送验证码 $result = $sms->mobile($mobile)->code($code)->send(); // 或者自定义短信内容 // $result = $sms->mobile($mobile)->content('恭喜您的材料已经审核成功,请及时查看。')->send(); if ($result === TRUE){ //短信验证码发送成功 }else{ //短信验证码发送失败 echo $sms->getError(); } 把短信扩展保存成php文件,修改其中的配置信息即可<?php /** * 互忆短信发送 * Class Huyisms * @package admin\huyisms\library */ class Huyisms { private $config = []; private $_params = []; public $error = ''; public function __construct($options = []) { $config = [ 'huyi_appid' => '', // todo 修改为你的 APPID 'huyi_appsecret' => '', // todo 修改为你的 APPSECRET 'huyi_temp' => '您的短信验证码为{$code},请勿向任何人提供此验证码。' // 默认短信验证码模板,不用备案,可以不修改 ]; $this->config = array_merge($config, is_array($options) ? $options : []); } /** * 发送短信方法 */ public function send() { $this->error = ''; $params = $this->_params(); $send_url = 'http://106.ihuyi.cn/webservice/sms.php?method=Submit&'; $response = $this->_curl($send_url,$params); if ($response !== FALSE){ $res = (array) json_decode($response,true); if (isset($res['code'])){ if ( $res['code'] == 2){ return TRUE; } } $this->error = isset($res['msg']) ? $res['msg'] : 'InvalidResultMsg'; }else{ $this->error = 'InvalidResult'; } return FALSE; } /** * 获取剩余短信条数 * @return mixed|string */ public function getNum() { $this->error = ''; $params = $this->_params(); $get_url = 'http://106.ihuyi.com/webservice/sms.php?method=GetNum&'; $response = $this->_curl($get_url,$params); if ($response !== FALSE){ $res = (array) json_decode($response,true); if (isset($res['code']) && $res['code'] == 2){ return $res['num']; } return $res['msg']; } return ''; } /** * 接收验证码值,不能和content同时使用 * @param string $code * @return $this */ public function code($code = '') { $content = str_replace('{$code}',$code,$this->config['huyi_temp']); $this->_params['content'] = $content; return $this; } /** * 接收短信内容 * @param string $content * @return $this */ public function content($content = '') { $this->_params['content'] = $content; return $this; } /** * 设置参数 * @param array $param * @return Huyisms */ public function param(array $param = []) { foreach ($param as $k => &$v) { $v = (string) $v; } unset($v); return $this; } /** * 接收手机 * @param string $mobile 手机号码 * @return Huyisms */ public function mobile($mobile = '') { $this->_params['mobile'] = $mobile; return $this; } /** * 返回错误信息 * @return string */ public function getError() { return $this->error; } private function _params() { return array_merge([ 'account' => $this->config['huyi_appid'], 'password' => $this->config['huyi_appsecret'], 'time' => time(), 'format' => 'json' ],$this->_params); } //请求数据到短信接口,检查环境是否 开启 curl init。 private function _curl($url,$params) { $uri = $url . http_build_query($params); $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_URL, $uri); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.98 Safari/537.36"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); $reponse = curl_exec($ch); curl_close($ch); return $reponse; } }
2019年01月14日
3,088 阅读
0 评论
0 点赞