Demo.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 test2(){
  39. $a = time();
  40. $b = $this->date_lang($a);
  41. dump($b);
  42. $b = $this->weekdatetime_lang($a);
  43. dump($b);
  44. }
  45. public function testweek(){
  46. $a = '1704609069';
  47. $b = date('w',$a);
  48. dump($b);
  49. $b = date('N',$a);
  50. dump($b);
  51. }
  52. public function test1(){
  53. $SnSclient = new SnsClient([
  54. 'profile' => 'default',
  55. 'region' => 'us-east-1',
  56. 'version' => '2010-03-31'
  57. ]);
  58. $subscription_token = 'arn:aws:sns:us-east-1:111122223333:MyTopic:123456-abcd-12ab-1234-12ba3dc1234a';
  59. $topic = 'arn:aws:sns:us-east-1:111122223333:MyTopic';
  60. try {
  61. $result = $SnSclient->confirmSubscription([
  62. 'Token' => $subscription_token,
  63. 'TopicArn' => $topic,
  64. ]);
  65. var_dump($result);
  66. } catch (AwsException $e) {
  67. // output error message if fails
  68. error_log($e->getMessage());
  69. }
  70. }
  71. public function test(){
  72. $out_trade_no = createUniqueNo('Test');
  73. $money = '1';
  74. $notifyurl = config('notify_cdnurl');
  75. $rs = $this->hitpay_payment($out_trade_no,$money,$notifyurl);
  76. dump($rs);
  77. //payorder 保存 $rs['id'] 为 payment_request_id
  78. }
  79. public function hitpay_payment($out_trade_no,$money,$notifyurl)
  80. {
  81. $return = [
  82. 'status' => false,
  83. 'msg' => '',
  84. 'url' => '',
  85. 'id' => 0,
  86. ];
  87. $apiKey = config('hitpay.apikey');
  88. try {
  89. $hitPayClient = new \HitPay\Client($apiKey, true);
  90. $request = new \HitPay\Request\CreatePayment();
  91. $request->setAmount($money)
  92. ->setCurrency('SGD')
  93. ->setPaymentMethods(['paynow_online','card'])
  94. ->setPurpose('Elin Dance Studio')
  95. ->setWebhook($notifyurl)
  96. ->setReferenceNumber($out_trade_no);
  97. $result = $hitPayClient->createPayment($request);
  98. $return['status'] = true;
  99. $return['url'] = $result->getUrl();
  100. $return['id'] = $result->getId();
  101. //print_r($result);
  102. /*$data = $hitPayClient->getPaymentStatus($result->getId());
  103. dump($data);
  104. dump($data->status);*/
  105. /*$data = $hitPayClient->deletePaymentRequest($data->getId());
  106. print_r($data);*/
  107. } catch (\Exception $e) {
  108. $return['msg'] = $e->getMessage();
  109. }
  110. return $return;
  111. }
  112. public function qixunyun_sms($mobile,$code){
  113. //配置
  114. $config = config('qixunyun_sms');
  115. $name = $config['name'];
  116. $password = $config['password'];
  117. $signname = $config['signname'];
  118. $url = 'https://api.hnsls5g.com/eums/sms/utf8/send.do';
  119. $seed = date('YmdHis');
  120. $content = '【'.$signname.'】Your verification Code is : ' . $code;
  121. $data = [
  122. 'name' => $name,
  123. 'seed' => $seed,
  124. 'key' => strtolower(md5(strtolower(md5($password)).$seed)),
  125. 'dest' => $mobile,
  126. 'content' => $content,
  127. ];
  128. $params = http_build_query($data);
  129. $url = $url.'?'.$params;
  130. $rs = curl_get($url);
  131. //dump($rs);
  132. //return $rs;
  133. //结果处理
  134. //$rs = 'error:111';
  135. //$rs = 'success:122617370809355265322';
  136. if(strpos($rs,'error:') === 0){
  137. $code = substr($rs,6);
  138. return $this->qixunyun_error($code);
  139. }
  140. if(strpos($rs,'success:') === 0){
  141. return true;
  142. }
  143. return '短信发送失败了';
  144. }
  145. public function newsms2(){
  146. $rs = $this->qixunyun_sms('18560505277','123456');
  147. dump($rs);
  148. }
  149. private function qixunyun_error($code){
  150. $array = [
  151. '101' => '缺少name参数',
  152. '102' => '缺少seed参数',
  153. '103' => '缺少key参数',
  154. '104' => '缺少dest参数',
  155. '105' => '缺少content参数',
  156. '106' => 'seed错误',
  157. '107' => 'key错误',
  158. '108' => 'ext错误',
  159. '109' => '内容超长',
  160. '110' => '模板未备案',
  161. '111' => '无签名',
  162. '112' => '缺少pk_total参数',
  163. '113' => '签名不合法',
  164. '114' => '定时时间格式错误',
  165. '115' => '定时时间范围错误',
  166. '116' => '不支持HTTP',
  167. '201' => '无对应账户',
  168. '202' => '账户暂停',
  169. '203' => '账户删除',
  170. '204' => '账户IP没备案',
  171. '205' => '账户无余额',
  172. '206' => '密码错误',
  173. '301' => '无对应产品',
  174. '302' => '产品暂停',
  175. '303' => '产品删除',
  176. '304' => '产品不在服务时间',
  177. '305' => '无匹配通道',
  178. '306' => '通道暂停',
  179. '307' => '通道已删除',
  180. '308' => '通道不在服务时间',
  181. '309' => '未提供短信服务',
  182. '401' => '屏蔽词',
  183. '500' => '查询间隔太短',
  184. '999' => '其他错误',
  185. ];
  186. $error = isset($array[$code]) ? $array[$code] : '短信发送失败';
  187. return $error;
  188. }
  189. public function whatsapp_cm(){
  190. $account_id = '657a5348-b28f-4736-8c76-6c47f4b20e4e';
  191. $daibi = '350448a7-e8bc-4310-8d5b-db3518a5d05e';
  192. $url = 'https://gw.cmtelecom.com/v1.0/message';
  193. $client = new \CMText\TextClient('your-api-key');
  194. echo json_encode(
  195. $client->SendMessage('Message_Text', 'CM.com', [ '15866999421' ], 'Your_Reference')
  196. );
  197. }
  198. public function whatapp(){
  199. //临时token
  200. $token = 'EAAGE5ozNog8BO8eXkmeAygGQqEBlIZCTwnPjnZAF7d0f1M5Q1t4IW3GGHAwceY8FR9vkCbZBRHlaMyhDPsFeVaZAFVCbolk4vKvJGMjeG6POOEmPilr5wRvNhjZAnTyYYLZBZBaKPC0mpgvzoVb4OjPA0fXnExlRfPZCg4tQAwxtkFk1UlQRuCchXbxXWDOxiZB05iadOSTf8leHmYeiTHe2hMvkZC4BkZBuIZCfmf1F3qafXZAsHw4uqFfiI';
  201. $token = 'EAAGE5ozNog8BO1ZCLYLW5b4Cl2CAu3YVMPV2jmuuoxxoFpkGmyxvMKZAMaVFTVZAVCFL4AH9MyYZCVezuPSgIxTMRMoZA1yFl5v3G7ZBcz0jXByGjajjWTyPaPnZBgeDrTDK0ZB2FS9aK9gXoftxNpBuklAWns0RAbnEE4aNOMzp2eel5JrkbBW0XFUZAghhzZB3fNnBI8OotMSZBN4NSZA0';
  202. //发送者
  203. $mobile_id = '279740441892291'; //test number :+1 555 609 4631, WhatsApp Business Account ID: 306946452494181
  204. $mobile_id = '308176785712131'; //Elin Dance Stuido:+65 8879 9689 , WhatsApp Business Account ID: 309484315581636
  205. $mobile_id = '337736419413019'; //Elin Dance Stuido 2:+65 8015 4154 , WhatsApp Business Account ID: 336509229537586
  206. //没用的东西
  207. $config_id = '321757761015767';
  208. //接收者
  209. $receive_mobile = '65' . '88799689';
  210. //$receive_mobile = '86' . '15866999421';
  211. //发送
  212. $url = 'https://graph.facebook.com/v19.0/'.$mobile_id.'/messages';
  213. $header = [
  214. 'Authorization: Bearer ' . $token,
  215. 'Content-Type: application/json',
  216. ];
  217. $body = [
  218. 'messaging_product' => 'whatsapp',
  219. 'recipient_type' => 'individual',
  220. 'to' => $receive_mobile,
  221. 'type' => 'template',
  222. 'template' => [
  223. // 'name' => 'the_class_will_start_tomorrow',
  224. 'name' => 'package_expiration_reminder',
  225. 'language' => [
  226. // 'code' => 'zh_CN',
  227. 'code' => 'en_US'
  228. ],
  229. 'components' => [
  230. [
  231. 'type' => 'body',
  232. 'parameters' => [
  233. [
  234. 'type' => 'text',
  235. 'text' => '张三',
  236. ],
  237. [
  238. 'type' => 'text',
  239. 'text' => '瑜伽课',
  240. ],
  241. [
  242. 'type' => 'text',
  243. 'text' => '2024-05-10 12:30',
  244. ],
  245. ],
  246. ]
  247. ],
  248. ],
  249. ];
  250. $body = json_encode($body);
  251. $rs = curl_post($url,$body,$header);
  252. dump($rs);
  253. }
  254. /*
  255. 套餐到期提醒
  256. Package expiration reminder
  257. Hi,{{1}},您购买的套餐{{2}}将于{{3}}过期,建议您在过期内使用完毕!
  258. Hi, {{1}}, the package {{2}} you purchased will expire on {{3}}. We recommend that you use it up within the expiration date!
  259. */
  260. }