作者 郭盛
1 个管道 的构建 通过 耗费 1 秒

短信接口

1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 <project version="4"> 2 <project version="4">
3 <component name="ChangeListManager"> 3 <component name="ChangeListManager">
4 - <list default="true" id="e93f11c2-a7d9-4d35-8b1c-8dd18e7f5fef" name="Default" comment="">  
5 - <change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />  
6 - <change type="MODIFICATION" beforePath="$PROJECT_DIR$/application/api/controller/Pay.php" afterPath="$PROJECT_DIR$/application/api/controller/Pay.php" />  
7 - <change type="MODIFICATION" beforePath="$PROJECT_DIR$/public/api.html" afterPath="$PROJECT_DIR$/public/api.html" />  
8 - </list> 4 + <list default="true" id="e93f11c2-a7d9-4d35-8b1c-8dd18e7f5fef" name="Default" comment="" />
9 <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> 5 <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
10 <option name="TRACKING_ENABLED" value="true" /> 6 <option name="TRACKING_ENABLED" value="true" />
11 <option name="SHOW_DIALOG" value="false" /> 7 <option name="SHOW_DIALOG" value="false" />
@@ -210,7 +206,7 @@ @@ -210,7 +206,7 @@
210 </component> 206 </component>
211 <component name="PhpWorkspaceProjectConfiguration" backward_compatibility_performed="true" /> 207 <component name="PhpWorkspaceProjectConfiguration" backward_compatibility_performed="true" />
212 <component name="ProjectFrameBounds" extendedState="1"> 208 <component name="ProjectFrameBounds" extendedState="1">
213 - <option name="x" value="148" /> 209 + <option name="x" value="141" />
214 <option name="y" value="49" /> 210 <option name="y" value="49" />
215 <option name="width" value="1776" /> 211 <option name="width" value="1776" />
216 <option name="height" value="1014" /> 212 <option name="height" value="1014" />
@@ -242,12 +238,6 @@ @@ -242,12 +238,6 @@
242 <item name="areial" type="2a2b976b:PhpTreeStructureProvider$1" /> 238 <item name="areial" type="2a2b976b:PhpTreeStructureProvider$1" />
243 <item name="application" type="2a2b976b:PhpTreeStructureProvider$1" /> 239 <item name="application" type="2a2b976b:PhpTreeStructureProvider$1" />
244 </path> 240 </path>
245 - <path>  
246 - <item name="areial" type="b2602c69:ProjectViewProjectNode" />  
247 - <item name="areial" type="2a2b976b:PhpTreeStructureProvider$1" />  
248 - <item name="application" type="2a2b976b:PhpTreeStructureProvider$1" />  
249 - <item name="nsms" type="2a2b976b:PhpTreeStructureProvider$1" />  
250 - </path>  
251 </expand> 241 </expand>
252 <select /> 242 <select />
253 </subPane> 243 </subPane>
@@ -310,7 +300,7 @@ @@ -310,7 +300,7 @@
310 <workItem from="1574469667436" duration="25235000" /> 300 <workItem from="1574469667436" duration="25235000" />
311 <workItem from="1574641631900" duration="15479000" /> 301 <workItem from="1574641631900" duration="15479000" />
312 <workItem from="1574669596135" duration="11747000" /> 302 <workItem from="1574669596135" duration="11747000" />
313 - <workItem from="1574727687281" duration="15410000" /> 303 + <workItem from="1574727687281" duration="15711000" />
314 </task> 304 </task>
315 <task id="LOCAL-00001" summary="调试"> 305 <task id="LOCAL-00001" summary="调试">
316 <created>1574145133364</created> 306 <created>1574145133364</created>
@@ -323,7 +313,7 @@ @@ -323,7 +313,7 @@
323 <servers /> 313 <servers />
324 </component> 314 </component>
325 <component name="TimeTrackingManager"> 315 <component name="TimeTrackingManager">
326 - <option name="totallyTimeSpent" value="245681000" /> 316 + <option name="totallyTimeSpent" value="245982000" />
327 </component> 317 </component>
328 <component name="TodoView"> 318 <component name="TodoView">
329 <todo-panel id="selected-file"> 319 <todo-panel id="selected-file">
@@ -335,16 +325,16 @@ @@ -335,16 +325,16 @@
335 </todo-panel> 325 </todo-panel>
336 </component> 326 </component>
337 <component name="ToolWindowManager"> 327 <component name="ToolWindowManager">
338 - <frame x="148" y="49" width="1776" height="1014" extended-state="1" /> 328 + <frame x="141" y="49" width="1776" height="1014" extended-state="1" />
339 <layout> 329 <layout>
340 - <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.14160839" sideWeight="0.5" order="1" side_tool="false" content_ui="combo" /> 330 + <window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.14160839" sideWeight="0.5" order="1" side_tool="false" content_ui="combo" />
341 <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32912987" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" /> 331 <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32912987" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
342 <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="true" content_ui="tabs" /> 332 <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="true" content_ui="tabs" />
343 <window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" /> 333 <window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
344 <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" /> 334 <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
345 <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" /> 335 <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
346 <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" /> 336 <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
347 - <window_info id="Terminal" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.12884834" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" /> 337 + <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.12884834" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
348 <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" /> 338 <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
349 <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="true" content_ui="tabs" /> 339 <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="true" content_ui="tabs" />
350 <window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" /> 340 <window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
  1 +<?php
  2 +namespace app\nsms;
  3 +date_default_timezone_set('PRC');//设置时区
  4 +/**
  5 + * 发送API
  6 + * demo仅供参考,demo最低运行环境PHP5.3
  7 + * 请确认开启PHP CURL 扩展
  8 + */
  9 +class sendAPI {
  10 + public $data; //发送数据
  11 + public $timeout = 30; //超时
  12 + private $apiUrl; //发送地址
  13 + private $username; //用户名
  14 + private $password; //密码
  15 +
  16 + function __construct($url, $username, $password) {
  17 + $this->apiUrl = $url;
  18 + $this->username = $username;
  19 + $this->password = $password;
  20 + }
  21 +
  22 + private function httpGet() {
  23 + $url = $this->apiUrl . '?' . http_build_query($this->data);
  24 + $curl = curl_init();
  25 + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  26 + curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
  27 + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  28 + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  29 + curl_setopt($curl, CURLOPT_URL, $url);
  30 + $res = curl_exec($curl);
  31 + if (curl_errno($curl)) {
  32 + echo 'Error GET '.curl_error($curl);
  33 + }
  34 + curl_close($curl);
  35 + return $res;
  36 + }
  37 +
  38 + private function httpPost(){ // 模拟提交数据函数
  39 + $curl = curl_init(); // 启动一个CURL会话
  40 + curl_setopt($curl, CURLOPT_URL, $this->apiUrl); // 要访问的地址
  41 + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
  42 + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
  43 + curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
  44 + curl_setopt($curl, CURLOPT_POST, true); // 发送一个常规的Post请求
  45 + curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($this->data)); // Post提交的数据包
  46 + curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout); // 设置超时限制防止死循环
  47 + curl_setopt($curl, CURLOPT_HEADER, false); // 显示返回的Header区域内容
  48 + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
  49 + $result = curl_exec($curl); // 执行操作
  50 + if (curl_errno($curl)) {
  51 + echo 'Error POST'.curl_error($curl);
  52 + }
  53 + curl_close($curl); // 关键CURL会话
  54 + return $result; // 返回数据
  55 + }
  56 +
  57 + /**
  58 + * @param $type|提交类型 POST/GET
  59 + * @param $isTranscoding|是否需要转 $isTranscoding 是否需要转utf-8 默认 false
  60 + * @return mixed
  61 + */
  62 + public function sendSMS($type, $isTranscoding = false) {
  63 + $this->data['content'] = $isTranscoding === true ? mb_convert_encoding($this->data['content'], "UTF-8") : $this->data['content'];
  64 + $this->data['username'] = $this->username;
  65 + $this->data['tkey'] = date('YmdHis');
  66 + $this->data['password'] = md5(md5($this->password) . $this->data['tkey']);
  67 + return $type == "POST" ? $this->httpPost() : $this->httpGet();
  68 + }
  69 +
  70 +}