Demo.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use Aws\Sns\SnsClient;
  5. use Aws\Exception\AwsException;
  6. /**
  7. * 示例接口
  8. */
  9. class Demo extends Api
  10. {
  11. //如果$noNeedLogin为空表示所有接口都需要登录才能请求
  12. //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
  13. //如果接口已经设置无需登录,那也就无需鉴权了
  14. //
  15. // 无需登录的接口,*表示全部
  16. protected $noNeedLogin = ['*'];
  17. // 无需鉴权的接口,*表示全部
  18. protected $noNeedRight = ['*'];
  19. /**
  20. * 测试方法
  21. *
  22. * @ApiTitle (测试名称)
  23. * @ApiSummary (测试描述信息)
  24. * @ApiMethod (POST)
  25. * @ApiRoute (/api/demo/test/id/{id}/name/{name})
  26. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  27. * @ApiParams (name="id", type="integer", required=true, description="会员ID")
  28. * @ApiParams (name="name", type="string", required=true, description="用户名")
  29. * @ApiParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
  30. * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  31. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  32. * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
  33. * @ApiReturn ({
  34. 'code':'1',
  35. 'msg':'返回成功'
  36. })
  37. */
  38. public function testweek(){
  39. $a = '1704609069';
  40. $b = date('w',$a);
  41. dump($b);
  42. $b = date('N',$a);
  43. dump($b);
  44. }
  45. public function test1(){
  46. $SnSclient = new SnsClient([
  47. 'profile' => 'default',
  48. 'region' => 'us-east-1',
  49. 'version' => '2010-03-31'
  50. ]);
  51. $subscription_token = 'arn:aws:sns:us-east-1:111122223333:MyTopic:123456-abcd-12ab-1234-12ba3dc1234a';
  52. $topic = 'arn:aws:sns:us-east-1:111122223333:MyTopic';
  53. try {
  54. $result = $SnSclient->confirmSubscription([
  55. 'Token' => $subscription_token,
  56. 'TopicArn' => $topic,
  57. ]);
  58. var_dump($result);
  59. } catch (AwsException $e) {
  60. // output error message if fails
  61. error_log($e->getMessage());
  62. }
  63. }
  64. public function test(){
  65. $out_trade_no = createUniqueNo('Test');
  66. $money = '1';
  67. $notifyurl = config('notify_cdnurl');
  68. $rs = $this->hitpay_payment($out_trade_no,$money,$notifyurl);
  69. dump($rs);
  70. //payorder 保存 $rs['id'] 为 payment_request_id
  71. }
  72. public function hitpay_payment($out_trade_no,$money,$notifyurl)
  73. {
  74. $return = [
  75. 'status' => false,
  76. 'msg' => '',
  77. 'url' => '',
  78. 'id' => 0,
  79. ];
  80. $apiKey = config('hitpay.apikey');
  81. try {
  82. $hitPayClient = new \HitPay\Client($apiKey, true);
  83. $request = new \HitPay\Request\CreatePayment();
  84. $request->setAmount($money)
  85. ->setCurrency('SGD')
  86. ->setPaymentMethods(['paynow_online','card'])
  87. ->setPurpose('Elin Dance Studio')
  88. ->setWebhook($notifyurl)
  89. ->setReferenceNumber($out_trade_no);
  90. $result = $hitPayClient->createPayment($request);
  91. $return['status'] = true;
  92. $return['url'] = $result->getUrl();
  93. $return['id'] = $result->getId();
  94. //print_r($result);
  95. /*$data = $hitPayClient->getPaymentStatus($result->getId());
  96. dump($data);
  97. dump($data->status);*/
  98. /*$data = $hitPayClient->deletePaymentRequest($data->getId());
  99. print_r($data);*/
  100. } catch (\Exception $e) {
  101. $return['msg'] = $e->getMessage();
  102. }
  103. return $return;
  104. }
  105. public function qixunyun_sms($mobile,$code){
  106. //配置
  107. $config = config('qixunyun_sms');
  108. $name = $config['name'];
  109. $password = $config['password'];
  110. $signname = $config['signname'];
  111. $url = 'https://api.hnsls5g.com/eums/sms/utf8/send.do';
  112. $seed = date('YmdHis');
  113. $content = '【'.$signname.'】Your verification Code is : ' . $code;
  114. $data = [
  115. 'name' => $name,
  116. 'seed' => $seed,
  117. 'key' => strtolower(md5(strtolower(md5($password)).$seed)),
  118. 'dest' => $mobile,
  119. 'content' => $content,
  120. ];
  121. $params = http_build_query($data);
  122. $url = $url.'?'.$params;
  123. $rs = curl_get($url);
  124. //dump($rs);
  125. //return $rs;
  126. //结果处理
  127. //$rs = 'error:111';
  128. //$rs = 'success:122617370809355265322';
  129. if(strpos($rs,'error:') === 0){
  130. $code = substr($rs,6);
  131. return $this->qixunyun_error($code);
  132. }
  133. if(strpos($rs,'success:') === 0){
  134. return true;
  135. }
  136. return '短信发送失败了';
  137. }
  138. public function newsms2(){
  139. $rs = $this->qixunyun_sms('18560505277','123456');
  140. dump($rs);
  141. }
  142. private function qixunyun_error($code){
  143. $array = [
  144. '101' => '缺少name参数',
  145. '102' => '缺少seed参数',
  146. '103' => '缺少key参数',
  147. '104' => '缺少dest参数',
  148. '105' => '缺少content参数',
  149. '106' => 'seed错误',
  150. '107' => 'key错误',
  151. '108' => 'ext错误',
  152. '109' => '内容超长',
  153. '110' => '模板未备案',
  154. '111' => '无签名',
  155. '112' => '缺少pk_total参数',
  156. '113' => '签名不合法',
  157. '114' => '定时时间格式错误',
  158. '115' => '定时时间范围错误',
  159. '116' => '不支持HTTP',
  160. '201' => '无对应账户',
  161. '202' => '账户暂停',
  162. '203' => '账户删除',
  163. '204' => '账户IP没备案',
  164. '205' => '账户无余额',
  165. '206' => '密码错误',
  166. '301' => '无对应产品',
  167. '302' => '产品暂停',
  168. '303' => '产品删除',
  169. '304' => '产品不在服务时间',
  170. '305' => '无匹配通道',
  171. '306' => '通道暂停',
  172. '307' => '通道已删除',
  173. '308' => '通道不在服务时间',
  174. '309' => '未提供短信服务',
  175. '401' => '屏蔽词',
  176. '500' => '查询间隔太短',
  177. '999' => '其他错误',
  178. ];
  179. $error = isset($array[$code]) ? $array[$code] : '短信发送失败';
  180. return $error;
  181. }
  182. public function whatsapp(){
  183. $account_id = '657a5348-b28f-4736-8c76-6c47f4b20e4e';
  184. $daibi = '350448a7-e8bc-4310-8d5b-db3518a5d05e';
  185. $url = 'https://gw.cmtelecom.com/v1.0/message';
  186. $client = new \CMText\TextClient('your-api-key');
  187. echo json_encode(
  188. $client->SendMessage('Message_Text', 'CM.com', [ '15866999421' ], 'Your_Reference')
  189. );
  190. }
  191. }