Demo.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use Aws\Sns\SnsClient;
  5. use Aws\Exception\AwsException;
  6. use app\common\library\Getui;
  7. use getui\GTClient;
  8. use getui\GTPushRequest;
  9. use getui\GTPushMessage;
  10. use getui\GTNotification;
  11. /**
  12. * 示例接口
  13. */
  14. class Demo extends Api
  15. {
  16. //如果$noNeedLogin为空表示所有接口都需要登录才能请求
  17. //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
  18. //如果接口已经设置无需登录,那也就无需鉴权了
  19. //
  20. // 无需登录的接口,*表示全部
  21. protected $noNeedLogin = ['*'];
  22. // 无需鉴权的接口,*表示全部
  23. protected $noNeedRight = ['*'];
  24. /**
  25. * 测试方法
  26. *
  27. * @ApiTitle (测试名称)
  28. * @ApiSummary (测试描述信息)
  29. * @ApiMethod (POST)
  30. * @ApiRoute (/api/demo/test/id/{id}/name/{name})
  31. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  32. * @ApiParams (name="id", type="integer", required=true, description="会员ID")
  33. * @ApiParams (name="name", type="string", required=true, description="用户名")
  34. * @ApiParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
  35. * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  36. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  37. * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
  38. * @ApiReturn ({
  39. 'code':'1',
  40. 'msg':'返回成功'
  41. })
  42. */
  43. public function getui2(){
  44. $config = config('getui');
  45. $this->appId = $config['gt_app_id'];
  46. $this->appKey = $config['gt_app_key'];
  47. $this->appSecret = $config['gt_app_secret'];
  48. $this->masterSecret = $config['gt_master_secret'];
  49. //创建API,APPID等配置参考 环境要求 进行获取
  50. $api = new GTClient("https://restapi.getui.com",$config['gt_app_key'], $config['gt_app_id'],$config['gt_master_secret']);
  51. //设置推送参数
  52. $push = new GTPushRequest();
  53. $push->setRequestId("请求唯一标识号");
  54. $message = new GTPushMessage();
  55. $notify = new GTNotification();
  56. $notify->setTitle("设置通知标题");
  57. $notify->setBody("设置通知内容");
  58. //点击通知后续动作,目前支持以下后续动作:
  59. //1、intent:打开应用内特定页面url:打开网页地址。2、payload:自定义消息内容启动应用。3、payload_custom:自定义消息内容不启动应用。4、startapp:打开应用首页。5、none:纯通知,无后续动作
  60. $notify->setClickType("none");
  61. $message->setNotification($notify);
  62. $push->setPushMessage($message);
  63. $push->setCid("CID");
  64. //处理返回结果
  65. $result = $api->pushApi()->pushToSingleByCid($push);
  66. }
  67. public function getui(){
  68. $getui = new Getui();
  69. $cid = 1;
  70. $title = '标题';
  71. $body = '内容';
  72. $ring_name = 'ringname';
  73. $type = 1;
  74. $platform = 'android';
  75. $getui->push($cid, $title, $body, $ring_name, $type, $platform);
  76. }
  77. public function createmsg(){
  78. $getui = new Getui();
  79. $title = '标题';
  80. $body = '内容';
  81. $type = 1;
  82. $rs = $getui->sendtoall($title, $body, $type);
  83. }
  84. public function test2(){
  85. $a = time();
  86. $b = $this->date_lang($a);
  87. dump($b);
  88. $b = $this->weekdatetime_lang($a);
  89. dump($b);
  90. }
  91. public function testweek(){
  92. $a = '1704609069';
  93. $b = date('w',$a);
  94. dump($b);
  95. $b = date('N',$a);
  96. dump($b);
  97. }
  98. public function test1(){
  99. $SnSclient = new SnsClient([
  100. 'profile' => 'default',
  101. 'region' => 'us-east-1',
  102. 'version' => '2010-03-31'
  103. ]);
  104. $subscription_token = 'arn:aws:sns:us-east-1:111122223333:MyTopic:123456-abcd-12ab-1234-12ba3dc1234a';
  105. $topic = 'arn:aws:sns:us-east-1:111122223333:MyTopic';
  106. try {
  107. $result = $SnSclient->confirmSubscription([
  108. 'Token' => $subscription_token,
  109. 'TopicArn' => $topic,
  110. ]);
  111. var_dump($result);
  112. } catch (AwsException $e) {
  113. // output error message if fails
  114. error_log($e->getMessage());
  115. }
  116. }
  117. public function test(){
  118. $out_trade_no = createUniqueNo('Test');
  119. $money = '1';
  120. $notifyurl = config('notify_cdnurl');
  121. $rs = $this->hitpay_payment($out_trade_no,$money,$notifyurl);
  122. dump($rs);
  123. //payorder 保存 $rs['id'] 为 payment_request_id
  124. }
  125. public function hitpay_payment($out_trade_no,$money,$notifyurl)
  126. {
  127. $return = [
  128. 'status' => false,
  129. 'msg' => '',
  130. 'url' => '',
  131. 'id' => 0,
  132. ];
  133. $apiKey = config('hitpay.apikey');
  134. try {
  135. $hitPayClient = new \HitPay\Client($apiKey, true);
  136. $request = new \HitPay\Request\CreatePayment();
  137. $request->setAmount($money)
  138. ->setCurrency('SGD')
  139. ->setPaymentMethods(['paynow_online','card'])
  140. ->setPurpose('Elin Dance Studio')
  141. ->setWebhook($notifyurl)
  142. ->setReferenceNumber($out_trade_no);
  143. $result = $hitPayClient->createPayment($request);
  144. $return['status'] = true;
  145. $return['url'] = $result->getUrl();
  146. $return['id'] = $result->getId();
  147. //print_r($result);
  148. /*$data = $hitPayClient->getPaymentStatus($result->getId());
  149. dump($data);
  150. dump($data->status);*/
  151. /*$data = $hitPayClient->deletePaymentRequest($data->getId());
  152. print_r($data);*/
  153. } catch (\Exception $e) {
  154. $return['msg'] = $e->getMessage();
  155. }
  156. return $return;
  157. }
  158. public function qixunyun_sms($mobile,$code){
  159. //配置
  160. $config = config('qixunyun_sms');
  161. $name = $config['name'];
  162. $password = $config['password'];
  163. $signname = $config['signname'];
  164. $url = 'https://api.hnsls5g.com/eums/sms/utf8/send.do';
  165. $seed = date('YmdHis');
  166. $content = '【'.$signname.'】Your verification Code is : ' . $code;
  167. $data = [
  168. 'name' => $name,
  169. 'seed' => $seed,
  170. 'key' => strtolower(md5(strtolower(md5($password)).$seed)),
  171. 'dest' => $mobile,
  172. 'content' => $content,
  173. ];
  174. $params = http_build_query($data);
  175. $url = $url.'?'.$params;
  176. $rs = curl_get($url);
  177. //dump($rs);
  178. //return $rs;
  179. //结果处理
  180. //$rs = 'error:111';
  181. //$rs = 'success:122617370809355265322';
  182. if(strpos($rs,'error:') === 0){
  183. $code = substr($rs,6);
  184. return $this->qixunyun_error($code);
  185. }
  186. if(strpos($rs,'success:') === 0){
  187. return true;
  188. }
  189. return '短信发送失败了';
  190. }
  191. public function newsms2(){
  192. $rs = $this->qixunyun_sms('18560505277','123456');
  193. dump($rs);
  194. }
  195. private function qixunyun_error($code){
  196. $array = [
  197. '101' => '缺少name参数',
  198. '102' => '缺少seed参数',
  199. '103' => '缺少key参数',
  200. '104' => '缺少dest参数',
  201. '105' => '缺少content参数',
  202. '106' => 'seed错误',
  203. '107' => 'key错误',
  204. '108' => 'ext错误',
  205. '109' => '内容超长',
  206. '110' => '模板未备案',
  207. '111' => '无签名',
  208. '112' => '缺少pk_total参数',
  209. '113' => '签名不合法',
  210. '114' => '定时时间格式错误',
  211. '115' => '定时时间范围错误',
  212. '116' => '不支持HTTP',
  213. '201' => '无对应账户',
  214. '202' => '账户暂停',
  215. '203' => '账户删除',
  216. '204' => '账户IP没备案',
  217. '205' => '账户无余额',
  218. '206' => '密码错误',
  219. '301' => '无对应产品',
  220. '302' => '产品暂停',
  221. '303' => '产品删除',
  222. '304' => '产品不在服务时间',
  223. '305' => '无匹配通道',
  224. '306' => '通道暂停',
  225. '307' => '通道已删除',
  226. '308' => '通道不在服务时间',
  227. '309' => '未提供短信服务',
  228. '401' => '屏蔽词',
  229. '500' => '查询间隔太短',
  230. '999' => '其他错误',
  231. ];
  232. $error = isset($array[$code]) ? $array[$code] : '短信发送失败';
  233. return $error;
  234. }
  235. public function whatsapp_cm(){
  236. $account_id = '657a5348-b28f-4736-8c76-6c47f4b20e4e';
  237. $daibi = '350448a7-e8bc-4310-8d5b-db3518a5d05e';
  238. $url = 'https://gw.cmtelecom.com/v1.0/message';
  239. $client = new \CMText\TextClient('your-api-key');
  240. echo json_encode(
  241. $client->SendMessage('Message_Text', 'CM.com', [ '15866999421' ], 'Your_Reference')
  242. );
  243. }
  244. public function whatapp(){
  245. //临时token
  246. $token = 'EAAGE5ozNog8BO8eXkmeAygGQqEBlIZCTwnPjnZAF7d0f1M5Q1t4IW3GGHAwceY8FR9vkCbZBRHlaMyhDPsFeVaZAFVCbolk4vKvJGMjeG6POOEmPilr5wRvNhjZAnTyYYLZBZBaKPC0mpgvzoVb4OjPA0fXnExlRfPZCg4tQAwxtkFk1UlQRuCchXbxXWDOxiZB05iadOSTf8leHmYeiTHe2hMvkZC4BkZBuIZCfmf1F3qafXZAsHw4uqFfiI';
  247. $token = 'EAAGE5ozNog8BO1ZCLYLW5b4Cl2CAu3YVMPV2jmuuoxxoFpkGmyxvMKZAMaVFTVZAVCFL4AH9MyYZCVezuPSgIxTMRMoZA1yFl5v3G7ZBcz0jXByGjajjWTyPaPnZBgeDrTDK0ZB2FS9aK9gXoftxNpBuklAWns0RAbnEE4aNOMzp2eel5JrkbBW0XFUZAghhzZB3fNnBI8OotMSZBN4NSZA0';
  248. //发送者
  249. $mobile_id = '279740441892291'; //test number :+1 555 609 4631, WhatsApp Business Account ID: 306946452494181
  250. $mobile_id = '308176785712131'; //Elin Dance Stuido:+65 8879 9689 , WhatsApp Business Account ID: 309484315581636
  251. $mobile_id = '337736419413019'; //Elin Dance Stuido 2:+65 8015 4154 , WhatsApp Business Account ID: 336509229537586
  252. //没用的东西
  253. $config_id = '321757761015767';
  254. //接收者
  255. $receive_mobile = '65' . '88799689';
  256. //$receive_mobile = '86' . '15866999421';
  257. //发送
  258. $url = 'https://graph.facebook.com/v19.0/'.$mobile_id.'/messages';
  259. $header = [
  260. 'Authorization: Bearer ' . $token,
  261. 'Content-Type: application/json',
  262. ];
  263. $body = [
  264. 'messaging_product' => 'whatsapp',
  265. 'recipient_type' => 'individual',
  266. 'to' => $receive_mobile,
  267. 'type' => 'template',
  268. 'template' => [
  269. // 'name' => 'the_class_will_start_tomorrow',
  270. 'name' => 'package_expiration_reminder',
  271. 'language' => [
  272. // 'code' => 'zh_CN',
  273. 'code' => 'en_US'
  274. ],
  275. 'components' => [
  276. [
  277. 'type' => 'body',
  278. 'parameters' => [
  279. [
  280. 'type' => 'text',
  281. 'text' => '张三',
  282. ],
  283. [
  284. 'type' => 'text',
  285. 'text' => '瑜伽课',
  286. ],
  287. [
  288. 'type' => 'text',
  289. 'text' => '2024-05-10 12:30',
  290. ],
  291. ],
  292. ]
  293. ],
  294. ],
  295. ];
  296. $body = json_encode($body);
  297. $rs = curl_post($url,$body,$header);
  298. dump($rs);
  299. }
  300. /*
  301. 套餐到期提醒
  302. Package expiration reminder
  303. Hi,{{1}},您购买的套餐{{2}}将于{{3}}过期,建议您在过期内使用完毕!
  304. Hi, {{1}}, the package {{2}} you purchased will expire on {{3}}. We recommend that you use it up within the expiration date!
  305. */
  306. }