这段PHP为啥短信发送无效
这段PHP为什么短信发送无效?
<br /><?php<br />set_time_limit(0);<br /> header("Content-Type: text/html; charset=GBK");<br /> /**<br /> * 定义程序绝对路径<br /> */<br /> define('SCRIPT_ROOT', dirname(__FILE__).'/');<br /> require_once SCRIPT_ROOT.'include/Client.php';<br />/**<br /> * 网关地址<br /> */ <br />$gwUrl = 'http://sdk.univetro.com.cn:6200/sdk/SDKService';<br /><br /><br />/**<br /> * 序列号,请通过联合维拓销售人员获取<br /> */<br />$serialNumber = '7SDK-LHW-0588-PFQUM';<br /><br />/**<br /> * 密码,请通过联合维拓销售人员获取<br /> */<br />$password = '814177';<br /><br />/**<br /> * 登录后所持有的SESSION KEY,即可通过login方法时创建<br /> */<br />$sessionKey = '063289';<br /><br />/**<br /> * 连接超时时间,单位为秒<br /> */<br />$connectTimeOut = 2;<br /><br />/**<br /> * 远程信息读取超时时间,单位为秒<br /> */ <br />$readTimeOut = 10;<br /><br />/**<br /> $proxyhost 可选,代理服务器地址,默认为 false ,则不使用代理服务器<br /> $proxyport 可选,代理服务器端口,默认为 false<br /> $proxyusername 可选,代理服务器用户名,默认为 false<br /> $proxypassword 可选,代理服务器密码,默认为 false<br />*/ <br /> $proxyhost = false;<br /> $proxyport = false;<br /> $proxyusername = false;<br /> $proxypassword = false; <br /><br />$client = new Client($gwUrl,$serialNumber,$password,$sessionKey,$proxyhost,$proxyport,$proxyusername,$proxypassword,$connectTimeOut,$readTimeOut);<br />/**<br /> * 发送向服务端的编码,如果本页面的编码为GBK,请使用GBK<br /> */<br />$client->setOutgoingEncoding("GBK");<br /><br />// login(); //激活序列号<br />// updatePassword(); //修改密码<br />// logout(); //注销序列号 <br />// registDetailInfo();//注册企业信息<br />// getEachFee(); //得到单价 <br />// getMO(); //接收短信<br />// getVersion(); //得到版本号 <br />// sendSMS(); //发送短信<br />// getBalance(); //得到余额<br />// chargeUp(); //充值<br /><br /><br />//----------------------------------------------------------------------<br />// 注: <br />// 1. 下面是各接口的使用用例,Client.php 还有每一个接口更详细的参数说明<br />// 2. 凡是返回 $statusCode 的, 都是相关操作的状态码<br />// 3. 由于php是弱类型语言,当服务端没返回时,也会等同认为 $statusCode=='0', 所以在判断时应该使用 if ($statusCode!=null && $statusCode==0) <br />//----------------------------------------------------------------------<br /><br /><br /><br /><br /><br /><br /><br />/**<br /> * 接口调用错误查看 用例<br /> */<br />function chkError()<br />{<br /> global $client;<br /> <br /> $err = $client->getError();<br /> if ($err)<br /> {<br /> /**<br /> * 调用出错,可能是网络原因,接口版本原因 等非业务上错误的问题导致的错误<br /> * 可在每个方法调用后查看,用于开发人员调试<br /> */<br /> <br /> echo $err;<br /> }<br /> <br />}<br /><br />/**<br /> * 登录 用例<br /> */<br />function login()<br />{<br /> global $client;<br /> <br /> /**<br /> * 下面的操作是产生随机6位数 session key<br /> * 注意: 如果要更换新的session key,则必须要求先成功执行 logout(注销操作)后才能更换<br /> * 我们建议 sesson key不用常变<br /> */<br /> //$sessionKey = $client->generateKey();<br /> //$statusCode = $client->login($sessionKey);<br /> <br /> $statusCode = $client->login();<br /> <br /> echo "处理状态码:".$statusCode."<br/>";<br /> if ($statusCode!=null && $statusCode=="0")<br /> {<br /> //登录成功,并且做保存 $sessionKey 的操作,用于以后相关操作的使用<br /> echo "登录成功, session key:".$client->getSessionKey()."<br/>";<br /> }else{<br /> //登录失败处理<br /> echo "登录失败";<br /> }<br /> <br />}<br /><br />/**<br /> * 注销登录 用例<br /> */<br />function logout()<br />{<br /> global $client;<br /><br /> $statusCode = $client->logout();<br /> echo "处理状态码:".$statusCode;<br />}<br /><br />/**<br /> * 获取版本号 用例<br /> */<br />function getVersion()<br />{<br /> global $client;<br /> <br /> echo "版本:". $client->getVersion();<br /> <br />}<br /> <br /> <br />/**<br /> * 取消短信转发 用例<br /> */ <br />function cancelMOForward()<br />{<br /> global $client;<br /> <br /><br /> $statusCode = $client->cancelMOForward();<br /> echo "处理状态码:".$statusCode;<br />}<br /><br />/**<br /> * 短信充值 用例<br /> */<br />function chargeUp()<br />{<br /> global $client;<br /> <br /> /**<br /> * $cardId [充值卡卡号]<br /> * $cardPass [密码]<br /> * <br /> * 请通过联合维拓销售人员获取 [充值卡卡号]长度为20内 [密码]长度为6<br /> * <br /> */<br /> <br /> $cardId = 'EMY00000000000000000';<br /> $cardPass = '000000';<br /> $statusCode = $client->chargeUp($cardId,$cardPass);<br /> echo "处理状态码:".$statusCode;<br />}<br /><br /><br />/**<br /> * 查询单条费用 用例<br /> */<br />function getEachFee()<br />{<br /> global $client;<br /> $fee = $client->getEachFee();<br /> echo "费用:".$fee;<br />}<br /><br /><br />/**<br /> * 企业注册 用例<br /> */<br />function registDetailInfo()<br />{<br /> global $client;<br /> <br /> $eName = "xx公司";<br /> $linkMan = "陈xx";<br /> $phoneNum = "010-1111111";<br /> $mobile = "18795551561";<br /> $email = "[email protected]";<br /> $fax = "010-1111111";<br /> $address = "xx路";<br /> $postcode = "111111";<br /> <br /> /**<br /> * 企业注册 [邮政编码]长度为6 其它参数长度为20以内<br /> * <br /> * @param string $eName 企业名称<br /> * @param string $linkMan 联系人姓名<br /> * @param string $phoneNum 联系电话<br /> * @param string $mobile 联系手机号码<br /> * @param string $email 联系电子邮件<br /> * @param string $fax 传真号码<br /> * @param string $address 联系地址<br /> * @param string $postcode 邮政编码<br /> * <br /> * @return int 操作结果状态码<br /> * <br /> */<br /> $statusCode = $client->registDetailInfo($eName,$linkMan,$phoneNum,$mobile,$email,$fax,$address,$postcode);<br /> echo "处理状态码:".$statusCode;<br /> <br />}<br /><br />/**<br /> * 更新密码 用例<br /> */<br />function updatePassword()<br />{<br /> global $client;<br /> <br /> /**<br /> * [密码]长度为6<br /> * <br /> * 如下面的例子是将密码修改成: 654321<br /> */<br /> $statusCode = $client->updatePassword('654321');<br /> echo "处理状态码:".$statusCode;<br />}<br /><br />/**<br /> * 短信转发 用例<br /> */<br />function setMOForward()<br />{<br /> <br /> global $client;<br /><br /> /**<br /> * 向 159xxxxxxxx 进行转发短信<br /> */ <br /> $statusCode = $client->setMOForward('18795551561');<br /> echo "处理状态码:".$statusCode;<br />}<br /><br />/**<br /> * 得到上行短信 用例<br /> */<br />function getMO()<br />{<br /> global $client;<br /> $moResult = $client->getMO();<br /> echo "返回数量:".count($moResult);<br /> foreach($moResult as $mo)<br /> {<br /> //$mo 是位于 Client.php 里的 Mo 对象<br /> // 实例代码为直接输出<br /> echo "发送者附加码:".$mo->getAddSerial();<br /> echo "接收者附加码:".$mo->getAddSerialRev();<br /> echo "通道号:".$mo->getChannelnumber();<br /> echo "手机号:".$mo->getMobileNumber();<br /> echo "发送时间:".$mo->getSentTime();<br /> <br /> /**<br /> * 由于服务端返回的编码是UTF-8,所以需要进行编码转换<br /> */<br /> echo "短信内容:".iconv("UTF-8","GBK",$mo->getSmsContent());<br /> <br /> // 上行短信务必要保存,加入业务逻辑代码,如:保存数据库,写文件等等<br /> }<br /> <br />}<br /><br />/**<br /> * 短信发送 用例<br /> */<br />function sendSMS($tel,$msg)<br />{<br /> global $client;<br /> /**<br /> * 下面的代码将发送内容为 test 给 159xxxxxxxx 和 159xxxxxxxx<br /> * $client->sendSMS还有更多可用参数,请参考 Client.php<br /> */<br /> /*$statusCode = $client->sendSMS(array('18136963895'),"【好网中国】尊敬的会员您好!感谢您注册好网中国,您的验证码是921057,请勿泄露您的验证码,如有疑问,请致电4000600011");*/<br /> $client->sendSMS($tel,$msg);<br /> //echo "处理状态码:".$statusCode;<br />}<br /><br />/**<br /> * 余额查询 用例<br /> */<br />function getBalance()<br />{<br /> global $client;<br /> $balance = $client->getBalance();<br /> echo "余额:".$balance;<br />}<br /><br />/**<br /> * 短信转发扩展 用例<br /> */<br />function setMOForwardEx()<br />{<br /> global $client;<br /><br /> /**<br /> * 向多个号码进行转发短信<br /> * <br /> * 以数组形式填写手机号码<br /> */ <br /> $statusCode = $client->setMOForwardEx(<br /> array('18795551561')<br /> );<br /> echo "处理状态码:".$statusCode;<br />}<br /> //login(); //激活序列号<br />// updatePassword(); //修改密码<br />// logout(); //注销序列号 <br /> //registDetailInfo();//注册企业信息<br />// getEachFee(); //得到单价 <br />// getMO(); //接收短信<br />// getVersion(); //得到版本号 <br />//sendSMS(); //发送短信<br />// getBalance(); //得到余额<br />// chargeUp(); //充值<br /><br /> if($_GET[type]=='sendmsg'){<br /> $msg="您好,感谢您在线申请注册银利多贵金属喊单直播间会员,您的手机验证码为:".$_POST[validate].",有效期3分钟。注册成功就可以免费获得资深分析师买卖点+仓位+止盈点+止损点明确操作建议,让您的投资利益最大化!详情请咨询0931-6180388【贵金属领航者--银利多】";<br /> $tel=array($_POST[telephone]);<br /> // $_POST[validate].$_POST[telephone];<br /> <br /> sendSMS($tel,$msg);<br /> echo 'success';<br /> }<br /> <br /> if($_GET[type]=='checkzh'){<br /> <br /> $msg="【好网中国】尊敬的会员您好!您的密码是".$_POST[password]."请勿泄露您的密码,如有疑问,请致电4000600011";<br /> $tel=array($_POST[telephone]);<br /> // $_POST[validate].$_POST[telephone];<br /> <br /> sendSMS($tel,$msg);<br /> echo 'success';<br /> }<br /><br />?><br /><br />
------解决思路----------------------
看看返回的數據與API文檔是否一致。
看看return code是什麼意思。
------解决思路----------------------
和我用的一个供应商的,第一次用的时候要手机执行了LOGO。以后就可以正常使用。
给你一个段片段
<br />$send_code="您的验证码是:".$_POST['send_code']."。请不要把验证码泄露给其他人!";<br /> $statusCode = $client->sendSMS(array("$mobile"),"$send_code");<br /> //echo $statusCode;<br /> if ($statusCode==0) {<br /> $data['msg']="提交成功";<br /> $data['status']=1;<br /> }else{<br /> $data="提交失败";<br /> $data['status']=0;<br /> }<br />
------解决思路----------------------
第一次用的时候要手动执行了Login。以后就可以正常使用。
------解决思路----------------------
你发送验证码,肯定会去请求url地址,看下返回什么东西。
------解决思路----------------------

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

By default, the title bar color on Windows 11 depends on the dark/light theme you choose. However, you can change it to any color you want. In this guide, we'll discuss step-by-step instructions for three ways to change it and personalize your desktop experience to make it visually appealing. Is it possible to change the title bar color of active and inactive windows? Yes, you can change the title bar color of active windows using the Settings app, or you can change the title bar color of inactive windows using Registry Editor. To learn these steps, go to the next section. How to change title bar color in Windows 11? 1. Using the Settings app press + to open the settings window. WindowsI go to "Personalization" and then

Taskbar thumbnails can be fun, but they can also be distracting or annoying. Considering how often you hover over this area, you may have inadvertently closed important windows a few times. Another disadvantage is that it uses more system resources, so if you've been looking for a way to be more resource efficient, we'll show you how to disable it. However, if your hardware specs can handle it and you like the preview, you can enable it. How to enable taskbar thumbnail preview in Windows 11? 1. Using the Settings app tap the key and click Settings. Windows click System and select About. Click Advanced system settings. Navigate to the Advanced tab and select Settings under Performance. Select "Visual Effects"

Do you see "A problem occurred" along with the "OOBELANGUAGE" statement on the Windows Installer page? The installation of Windows sometimes stops due to such errors. OOBE means out-of-the-box experience. As the error message indicates, this is an issue related to OOBE language selection. There is nothing to worry about, you can solve this problem with nifty registry editing from the OOBE screen itself. Quick Fix – 1. Click the “Retry” button at the bottom of the OOBE app. This will continue the process without further hiccups. 2. Use the power button to force shut down the system. After the system restarts, OOBE should continue. 3. Disconnect the system from the Internet. Complete all aspects of OOBE in offline mode

We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

The activation process on Windows sometimes takes a sudden turn to display an error message containing this error code 0xc004f069. Although the activation process is online, some older systems running Windows Server may experience this issue. Go through these initial checks, and if they don't help you activate your system, jump to the main solution to resolve the issue. Workaround – close the error message and activation window. Then restart the computer. Retry the Windows activation process from scratch again. Fix 1 – Activate from Terminal Activate Windows Server Edition system from cmd terminal. Stage – 1 Check Windows Server Version You have to check which type of W you are using
