作为一个优秀的打工人,PHP - HTTP_Request2接入短信验证码还不是手到擒来 前段时间,打工人的梗突然的火了起来:打工人打工魂,打工都是人上人。 作为资深打工人,今天给大家分享PHP - HTTP_Request2接入短信验证码的示例,希望大家可以用的上:
- <?php
- require_once 'HTTP/Request2.php';
- $request = new HTTP_Request2();
- $request->setUrl('https://vip.veesing.com/smsAp...');
- $request->setMethod(HTTP_Request2::METHOD_POST);
- $request->setConfig(array(
- 'follow_redirects' => TRUE
- ));
- $request->setHeader(array(
- 'Content-Type' => 'application/x-www-form-urlencoded;charset=utf-8'
- ));
- $request->addPostParameter(array(
- 'appId' => '41KYR0EB**',
- 'appKey' => 'IIWCKKSR7NOQ**',
- 'phone' => '1561894**',
- 'templateId' => '1043',
- 'variables' => '1234'
- ));
- try {
- response =response=request->send();
- if ($response->getStatus() == 200) {
- echo $response->getBody();
- }
- else {
- echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
- $response->getReasonPhrase();
- }
- }
- catch(HTTP_Request2_Exception $e) {
- echo 'Error: ' . $e->getMessage();
- }
复制代码
以上就是PHP - HTTP_Request2接入短信验证码的示例,觉得有用就收藏一下吧,万一哪天需要,然后又找不到了呢!
|