介绍
这篇文章将为大家详细讲解有关php短信接口代码是什么,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
<强> 1。短信调用类,,强>
& lt; php ?/* * *用户:管理员 *日期:2016/5/8 0008 *时间:下午第2章36节 */类短信{//Luosimao api键 私人$ _api_key=& # 39; & # 39;; 私人数组$ _last_error=(); 私人_use_ssl美元=FALSE; 私人$ _ssl_api_url=阵列( & # 39;发送# 39;=比;& # 39;https://www.jb51.net/v1/send.json& # 39; & # 39;send_batch& # 39;=比;& # 39;https://www.jb51.net/v1/send_batch.json& # 39; & # 39;状态# 39;=比;& # 39;https://www.jb51.net/v1/status.json& # 39; ); 私人$ _api_url=阵列( & # 39;发送# 39;=比;& # 39;https://www.jb51.net/v1/send.json& # 39; & # 39;send_batch& # 39;=比;& # 39;https://www.jb51.net/send_batch.json& # 39; & # 39;状态# 39;=比;& # 39;https://www.jb51.net/v1/status.json& # 39; );/* * * @param数组$参数配置参数 * api_key api秘钥,在luosimao短信后台短信→触发发送下面可查看 * use_ssl启用HTTPS地址,HTTPS有一定性能损耗,可选,默认不启用 */公共函数__construct (param美元=array ()) { 如果(!收取($参数[& # 39;api_key # 39;])) { 死亡(“api键错误!”); } 如果收取(param美元[& # 39;api_key # 39;])) { $ this→_api_key=$参数(& # 39;api_key # 39;); } 如果收取(param美元[& # 39;use_ssl& # 39;])) { $ this→_use_ssl=$参数(& # 39;use_ssl& # 39;); } }//触发,单发,适用于验证码,订单触发提醒类 公共函数发送(移动消息美元=& # 39;& # 39;){ api_url=!这→美元_use_ssl吗?$ this→_api_url[& # 39;发送# 39;]:$ this→_ssl_api_url[& # 39;发送# 39;]; $参数=阵列( & # 39;移动# 39;=比;美元的移动, & # 39;消息# 39;=比;美元的消息, ); res=这→美元http_post (api_url, param美元); 返回@json_decode (res美元,真实); }//批量发送,用于大批量发送 公共函数send_batch (mobile_list=array(),消息=美元数组(),$时间=& # 39;& # 39;){ api_url=!这→美元_use_ssl吗?$ this→_api_url [& # 39; send_batch& # 39;]: $ this→_ssl_api_url [& # 39; send_batch& # 39;]; (mobile_list=is_array美元mobile_list) ?内爆(& # 39;& # 39;mobile_list):美元,mobile_list; $参数=阵列( & # 39;mobile_list& # 39;=比;mobile_list美元, & # 39;消息# 39;=比;美元的消息, & # 39;时间# 39;=比;时间,美元 ); res=这→美元http_post (api_url, param美元); 返回@json_decode (res美元,真实); }//获取短信账号余额 公共函数get_deposit () { api_url=!这→美元_use_ssl吗?$ this→_api_url[& # 39;状态# 39;]:$ this→_ssl_api_url[& # 39;状态# 39;]; res=这→美元http_get ($ api_url); 返回@json_decode (res美元,真实); }/* * 美元* @param字符串类型接收类型,用于在服务器端接收上行和发送状态,接收地址需要在luosimao后台设置 * @param数组$参数传入的参数,从推送的url中获取,官方文档:https://luosimao.com/docs/api/*/公共函数recv ($ type=& # 39;状态# 39;数组$参数=()){ 如果($ type==& # 39;状态# 39;){ if($参数[& # 39;batch_id& # 39;),,$参数[& # 39;移动# 39;),,$参数[& # 39;状态# 39;)){//状态//做记录 } }elseif ($ type==& # 39;输入# 39;){//上行回复 if($参数[& # 39;移动# 39;),,$参数[& # 39;消息# 39;)){//做记录 } } }/* * * @param字符串$ api_url接口地址 * @param数组$参数后参数 * @param int超时超美元时时间 * @return bool */私有函数http_post ($ api_url=& # 39; & # 39;,参数数组=(),超时美元=5){ 如果(! $ api_url) { 死亡(“错误api_url"); } $ ch=curl_init (); curl_setopt ($ ch CURLOPT_URL api_url美元); curl_setopt ($ ch CURLOPT_HTTP_VERSION CURL_HTTP_VERSION_1_0); curl_setopt ($ ch CURLOPT_CONNECTTIMEOUT超时美元); curl_setopt ($ ch CURLOPT_RETURNTRANSFER真实); curl_setopt ($ ch CURLOPT_HEADER假); 如果(parse_url (api_url美元)[& # 39;计划# 39;]==& # 39;https # 39;) { curl_setopt ($ ch CURLOPT_SSL_VERIFYHOST假); curl_setopt ($ ch CURLOPT_SSL_VERIFYPEER假); } curl_setopt ($ ch CURLOPT_HTTPAUTH CURLAUTH_BASIC); curl_setopt ($ ch CURLOPT_USERPWD & # 39; api:关键& # 39;。$ this→_api_key); curl_setopt ($ ch CURLOPT_POST真实); curl_setopt ($ ch CURLOPT_POSTFIELDS param美元); (res=curl_exec美元ch); (错误=curl_error美元ch); curl_close (ch); 如果美元(错误){ $ this→_last_error[]=$错误; 返回错误; } 返回res美元; }/* * * @param字符串$ api_url接口地址 * @param字符串$超时超时时间 * @return bool */私有函数http_get ($ api_url=& # 39; & # 39;$超时=& # 39;& # 39;){ 如果(! $ api_url) { 死亡(“错误api_url"); } $ ch=curl_init (); curl_setopt ($ ch CURLOPT_URL api_url美元); curl_setopt ($ ch CURLOPT_HTTP_VERSION CURL_HTTP_VERSION_1_0); curl_setopt ($ ch CURLOPT_CONNECTTIMEOUT超时美元); curl_setopt ($ ch CURLOPT_RETURNTRANSFER真实); curl_setopt ($ ch CURLOPT_HEADER假); 如果(parse_url (api_url美元)[& # 39;计划# 39;]==& # 39;https # 39;) { curl_setopt ($ ch CURLOPT_SSL_VERIFYHOST假); curl_setopt ($ ch CURLOPT_SSL_VERIFYPEER假); } curl_setopt ($ ch CURLOPT_HTTPAUTH CURLAUTH_BASIC); curl_setopt ($ ch CURLOPT_USERPWD & # 39; api:关键& # 39;。$ this→_api_key); (res=curl_exec美元ch); (错误=curl_error美元ch); curl_close (ch); 如果美元(错误){ $ this→_last_error []=curl_error (ch); 返回错误; } 返回res美元; } 公共函数last_error () { 返回$ this→_last_error; } }php短信接口代码是什么