Demo.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 test1(){
  39. $SnSclient = new SnsClient([
  40. 'profile' => 'default',
  41. 'region' => 'us-east-1',
  42. 'version' => '2010-03-31'
  43. ]);
  44. $subscription_token = 'arn:aws:sns:us-east-1:111122223333:MyTopic:123456-abcd-12ab-1234-12ba3dc1234a';
  45. $topic = 'arn:aws:sns:us-east-1:111122223333:MyTopic';
  46. try {
  47. $result = $SnSclient->confirmSubscription([
  48. 'Token' => $subscription_token,
  49. 'TopicArn' => $topic,
  50. ]);
  51. var_dump($result);
  52. } catch (AwsException $e) {
  53. // output error message if fails
  54. error_log($e->getMessage());
  55. }
  56. }
  57. public function test(){
  58. $out_trade_no = createUniqueNo('Test');
  59. $money = '1';
  60. $notifyurl = config('notify_cdnurl');
  61. $rs = $this->hitpay_payment($out_trade_no,$money,$notifyurl);
  62. dump($rs);
  63. //payorder 保存 $rs['id'] 为 payment_request_id
  64. }
  65. public function hitpay_payment($out_trade_no,$money,$notifyurl)
  66. {
  67. $return = [
  68. 'status' => false,
  69. 'msg' => '',
  70. 'url' => '',
  71. 'id' => 0,
  72. ];
  73. $apiKey = config('hitpay.apikey');
  74. try {
  75. $hitPayClient = new \HitPay\Client($apiKey, true);
  76. $request = new \HitPay\Request\CreatePayment();
  77. $request->setAmount($money)
  78. ->setCurrency('SGD')
  79. ->setPaymentMethods(['paynow_online','card'])
  80. ->setPurpose('Elin Dance Studio')
  81. ->setWebhook($notifyurl)
  82. ->setReferenceNumber($out_trade_no);
  83. $result = $hitPayClient->createPayment($request);
  84. $return['status'] = true;
  85. $return['url'] = $result->getUrl();
  86. $return['id'] = $result->getId();
  87. //print_r($result);
  88. /*$data = $hitPayClient->getPaymentStatus($result->getId());
  89. dump($data);
  90. dump($data->status);*/
  91. /*$data = $hitPayClient->deletePaymentRequest($data->getId());
  92. print_r($data);*/
  93. } catch (\Exception $e) {
  94. $return['msg'] = $e->getMessage();
  95. }
  96. return $return;
  97. }
  98. public function qixunyun_sms($mobile,$code){
  99. //配置
  100. $config = config('qixunyun_sms');
  101. $name = $config['name'];
  102. $password = $config['password'];
  103. $signname = $config['signname'];
  104. $url = 'https://api.hnsls5g.com/eums/sms/utf8/send.do';
  105. $seed = date('YmdHis');
  106. $content = '【'.$signname.'】Your verification Code is : ' . $code;
  107. $data = [
  108. 'name' => $name,
  109. 'seed' => $seed,
  110. 'key' => strtolower(md5(strtolower(md5($password)).$seed)),
  111. 'dest' => $mobile,
  112. 'content' => $content,
  113. ];
  114. $params = http_build_query($data);
  115. $url = $url.'?'.$params;
  116. $rs = curl_get($url);
  117. //dump($rs);
  118. //return $rs;
  119. //结果处理
  120. //$rs = 'error:111';
  121. //$rs = 'success:122617370809355265322';
  122. if(strpos($rs,'error:') === 0){
  123. $code = substr($rs,6);
  124. return $this->qixunyun_error($code);
  125. }
  126. if(strpos($rs,'success:') === 0){
  127. return true;
  128. }
  129. return '短信发送失败了';
  130. }
  131. public function newsms2(){
  132. $rs = $this->qixunyun_sms('18560505277','123456');
  133. dump($rs);
  134. }
  135. private function qixunyun_error($code){
  136. $array = [
  137. '101' => '缺少name参数',
  138. '102' => '缺少seed参数',
  139. '103' => '缺少key参数',
  140. '104' => '缺少dest参数',
  141. '105' => '缺少content参数',
  142. '106' => 'seed错误',
  143. '107' => 'key错误',
  144. '108' => 'ext错误',
  145. '109' => '内容超长',
  146. '110' => '模板未备案',
  147. '111' => '无签名',
  148. '112' => '缺少pk_total参数',
  149. '113' => '签名不合法',
  150. '114' => '定时时间格式错误',
  151. '115' => '定时时间范围错误',
  152. '116' => '不支持HTTP',
  153. '201' => '无对应账户',
  154. '202' => '账户暂停',
  155. '203' => '账户删除',
  156. '204' => '账户IP没备案',
  157. '205' => '账户无余额',
  158. '206' => '密码错误',
  159. '301' => '无对应产品',
  160. '302' => '产品暂停',
  161. '303' => '产品删除',
  162. '304' => '产品不在服务时间',
  163. '305' => '无匹配通道',
  164. '306' => '通道暂停',
  165. '307' => '通道已删除',
  166. '308' => '通道不在服务时间',
  167. '309' => '未提供短信服务',
  168. '401' => '屏蔽词',
  169. '500' => '查询间隔太短',
  170. '999' => '其他错误',
  171. ];
  172. $error = isset($array[$code]) ? $array[$code] : '短信发送失败';
  173. return $error;
  174. }
  175. public function whatsapp(){
  176. $account_id = '657a5348-b28f-4736-8c76-6c47f4b20e4e';
  177. $daibi = '350448a7-e8bc-4310-8d5b-db3518a5d05e';
  178. $url = 'https://gw.cmtelecom.com/v1.0/message';
  179. $client = new \CMText\TextClient('your-api-key');
  180. echo json_encode(
  181. $client->SendMessage('Message_Text', 'CM.com', [ '15866999421' ], 'Your_Reference')
  182. );
  183. }
  184. }