Demo.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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 think\Db;
  8. use app\common\library\Email;
  9. use getui\GTClient;
  10. use getui\GTPushRequest;
  11. use getui\GTPushMessage;
  12. use getui\GTNotification;
  13. /**
  14. * 示例接口
  15. */
  16. class Demo extends Api
  17. {
  18. //如果$noNeedLogin为空表示所有接口都需要登录才能请求
  19. //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
  20. //如果接口已经设置无需登录,那也就无需鉴权了
  21. //
  22. // 无需登录的接口,*表示全部
  23. protected $noNeedLogin = ['*'];
  24. // 无需鉴权的接口,*表示全部
  25. protected $noNeedRight = ['*'];
  26. /**
  27. * 测试方法
  28. *
  29. * @ApiTitle (测试名称)
  30. * @ApiSummary (测试描述信息)
  31. * @ApiMethod (POST)
  32. * @ApiRoute (/api/demo/test/id/{id}/name/{name})
  33. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  34. * @ApiParams (name="id", type="integer", required=true, description="会员ID")
  35. * @ApiParams (name="name", type="string", required=true, description="用户名")
  36. * @ApiParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
  37. * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  38. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  39. * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
  40. * @ApiReturn ({
  41. 'code':'1',
  42. 'msg':'返回成功'
  43. })
  44. */
  45. public function auto_lesson_slot_notice(){
  46. $order = [
  47. 'firstname' => '振',
  48. 'lastname' => '李',
  49. 'email' => '1129121659@qq.com',
  50. 'name_en' => '蹦极',
  51. ];
  52. $slot = [
  53. 'starttime' => time(),
  54. ];
  55. $message =
  56. 'Hi,'.$order['firstname']. ' ' .$order['lastname'].'!<br/>
  57. We are looking forward to seeing you at the following class tomorrow!<br/>
  58. Class:'.$order['name_en'].'<br/>
  59. Date: '.date('d F Y',$slot['starttime']).'<br/>
  60. Time: '.date('H:i a',$slot['starttime']).'<br/>
  61. Please arrive 10 minutes before the class timing to prepare for the harness fitting!<br/>
  62. We are located at 450 Alexandra Road, #02-01,<br/>
  63. Singapore 119960. For those who are driving, parking is available on level 2 of the building. For those who are taking public transport, the nearest mrt is Labrador Park MRT (7-10 minutes walk) and there is also a bus stop available just outside the building!<br/>
  64. We look forward to seeing you for an amazing session! ❤<br/>
  65. Best Regards,<br/>
  66. Elin Dance Studio<br/>
  67. <img src="'.config('website_url').'/assets/img/logo3.png" style="width:136px;height:115px">
  68. ';
  69. $obj = new Email();
  70. $result = $obj
  71. ->to($order['email'])
  72. ->subject('You have a class tomorrow!')
  73. ->message($message)
  74. ->send();
  75. dump($result);
  76. }
  77. public function auto_package_order_notice_mon(){
  78. $order = [
  79. 'firstname' => '振',
  80. 'lastname' => '李',
  81. 'email' => '1129121659@qq.com',
  82. 'name_en' => '蹦极100节',
  83. 'endtime' => time(),
  84. ];
  85. $slot = [
  86. 'starttime' => time(),
  87. ];
  88. $message =
  89. 'Hi,'.$order['firstname']. ' ' .$order['lastname'].'!<br/>
  90. Thank you for your purchase of the '.$order['name_en'].' plan!<br/>
  91. <b>Please note</b>: Plans that are 5 hours and above need to be activated by us! This is so that you can use up your current plans first (if any)!<br/>
  92. When you wish to activate, please send a WhatsApp message to 8879-9689 to activate your package to start booking classes.<br/>
  93. Once activated, your plan’s validity period will begin.<br/>
  94. You can view the unactivated packages in the app.<br/>
  95. We look forward to seeing you soon!❤<br/>
  96. Best Regards,<br/>
  97. Elin Dance Studio<br/>
  98. <img src="'.config('website_url').'/assets/img/logo3.png" style="width:136px;height:115px">
  99. ';
  100. //给这些用户发邮件
  101. $obj = new Email();
  102. $result = $obj
  103. ->to($order['email'])
  104. ->subject('Your plan purchase has been received!')
  105. ->message($message)
  106. ->send();
  107. dump($result);
  108. }
  109. public function hitpay_redirect_log(){
  110. $url = input('url','');
  111. $data = [
  112. 'url' => $url,
  113. 'createdate' => date('Y-m-d H:i:s'),
  114. ];
  115. Db::name('hitpay_redirect_log')->insertGetId($data);
  116. $this->success(1);
  117. }
  118. public function getui2(){
  119. $config = config('getui');
  120. $this->appId = $config['gt_app_id'];
  121. $this->appKey = $config['gt_app_key'];
  122. $this->appSecret = $config['gt_app_secret'];
  123. $this->masterSecret = $config['gt_master_secret'];
  124. //创建API,APPID等配置参考 环境要求 进行获取
  125. $api = new GTClient("https://restapi.getui.com",$config['gt_app_key'], $config['gt_app_id'],$config['gt_master_secret']);
  126. //设置推送参数
  127. $push = new GTPushRequest();
  128. $push->setRequestId("请求唯一标识号");
  129. $message = new GTPushMessage();
  130. $notify = new GTNotification();
  131. $notify->setTitle("设置通知标题");
  132. $notify->setBody("设置通知内容");
  133. //点击通知后续动作,目前支持以下后续动作:
  134. //1、intent:打开应用内特定页面url:打开网页地址。2、payload:自定义消息内容启动应用。3、payload_custom:自定义消息内容不启动应用。4、startapp:打开应用首页。5、none:纯通知,无后续动作
  135. $notify->setClickType("none");
  136. $message->setNotification($notify);
  137. $push->setPushMessage($message);
  138. $push->setCid("CID");
  139. //处理返回结果
  140. $result = $api->pushApi()->pushToSingleByCid($push);
  141. }
  142. public function getui(){
  143. $getui = new Getui();
  144. $cid = 1;
  145. $title = '标题';
  146. $body = '内容';
  147. $ring_name = 'ringname';
  148. $type = 1;
  149. $platform = 'android';
  150. $getui->push($cid, $title, $body, $ring_name, $type, $platform);
  151. }
  152. public function sendtoall(){
  153. $getui = new Getui();
  154. $title = '我是群发标题11222';
  155. $body = '接下来两周的课程将于今天下午 6.45 发布22333';
  156. $rs = $getui->sendtoall($title, $body, 1, 'android');
  157. $rs = $getui->sendtoall($title, $body, 1, 'ios');
  158. }
  159. public function test2(){
  160. $a = time();
  161. $b = $this->date_lang($a);
  162. dump($b);
  163. $b = $this->weekdatetime_lang($a);
  164. dump($b);
  165. }
  166. public function testweek(){
  167. $a = '1704609069';
  168. $b = date('w',$a);
  169. dump($b);
  170. $b = date('N',$a);
  171. dump($b);
  172. }
  173. public function test1(){
  174. $SnSclient = new SnsClient([
  175. 'profile' => 'default',
  176. 'region' => 'us-east-1',
  177. 'version' => '2010-03-31'
  178. ]);
  179. $subscription_token = 'arn:aws:sns:us-east-1:111122223333:MyTopic:123456-abcd-12ab-1234-12ba3dc1234a';
  180. $topic = 'arn:aws:sns:us-east-1:111122223333:MyTopic';
  181. try {
  182. $result = $SnSclient->confirmSubscription([
  183. 'Token' => $subscription_token,
  184. 'TopicArn' => $topic,
  185. ]);
  186. var_dump($result);
  187. } catch (AwsException $e) {
  188. // output error message if fails
  189. error_log($e->getMessage());
  190. }
  191. }
  192. public function test(){
  193. $out_trade_no = createUniqueNo('Test');
  194. $money = '1';
  195. $notifyurl = config('notify_cdnurl');
  196. $rs = $this->hitpay_payment($out_trade_no,$money,$notifyurl);
  197. dump($rs);
  198. //payorder 保存 $rs['id'] 为 payment_request_id
  199. }
  200. public function hitpay_getstatus(){
  201. $payment_request_id = '9d0f79b7-68b1-4065-b5e5-75e8cd6a3a4c';
  202. $apiKey = config('hitpay.apikey');
  203. $hitPayClient = new \HitPay\Client($apiKey, true);
  204. $data = $hitPayClient->getPaymentStatus($payment_request_id);
  205. dump($data);
  206. dump($data->status);
  207. }
  208. public function hitpay_payment($out_trade_no,$money,$notifyurl)
  209. {
  210. $return = [
  211. 'status' => false,
  212. 'msg' => '',
  213. 'url' => '',
  214. 'id' => 0,
  215. ];
  216. $apiKey = config('hitpay.apikey');
  217. try {
  218. $hitPayClient = new \HitPay\Client($apiKey, true);
  219. $request = new \HitPay\Request\CreatePayment();
  220. $request->setAmount($money)
  221. ->setCurrency('SGD')
  222. ->setPaymentMethods(['paynow_online','card'])
  223. ->setPurpose('Elin Dance Studio')
  224. ->setWebhook($notifyurl)
  225. ->setReferenceNumber($out_trade_no);
  226. $result = $hitPayClient->createPayment($request);
  227. $return['status'] = true;
  228. $return['url'] = $result->getUrl();
  229. $return['id'] = $result->getId();
  230. //print_r($result);
  231. /*$data = $hitPayClient->getPaymentStatus($result->getId());
  232. dump($data);
  233. dump($data->status);*/
  234. /*$data = $hitPayClient->deletePaymentRequest($data->getId());
  235. print_r($data);*/
  236. } catch (\Exception $e) {
  237. $return['msg'] = $e->getMessage();
  238. }
  239. return $return;
  240. }
  241. public function qixunyun_sms($mobile,$code){
  242. //配置
  243. $config = config('qixunyun_sms');
  244. $name = $config['name'];
  245. $password = $config['password'];
  246. $signname = $config['signname'];
  247. $url = 'https://api.hnsls5g.com/eums/sms/utf8/send.do';
  248. $seed = date('YmdHis');
  249. $content = '【'.$signname.'】Your verification Code is : ' . $code;
  250. $data = [
  251. 'name' => $name,
  252. 'seed' => $seed,
  253. 'key' => strtolower(md5(strtolower(md5($password)).$seed)),
  254. 'dest' => $mobile,
  255. 'content' => $content,
  256. ];
  257. $params = http_build_query($data);
  258. $url = $url.'?'.$params;
  259. $rs = curl_get($url);
  260. //dump($rs);
  261. //return $rs;
  262. //结果处理
  263. //$rs = 'error:111';
  264. //$rs = 'success:122617370809355265322';
  265. if(strpos($rs,'error:') === 0){
  266. $code = substr($rs,6);
  267. return $this->qixunyun_error($code);
  268. }
  269. if(strpos($rs,'success:') === 0){
  270. return true;
  271. }
  272. return '短信发送失败了';
  273. }
  274. public function newsms2(){
  275. $rs = $this->qixunyun_sms('18560505277','123456');
  276. dump($rs);
  277. }
  278. private function qixunyun_error($code){
  279. $array = [
  280. '101' => '缺少name参数',
  281. '102' => '缺少seed参数',
  282. '103' => '缺少key参数',
  283. '104' => '缺少dest参数',
  284. '105' => '缺少content参数',
  285. '106' => 'seed错误',
  286. '107' => 'key错误',
  287. '108' => 'ext错误',
  288. '109' => '内容超长',
  289. '110' => '模板未备案',
  290. '111' => '无签名',
  291. '112' => '缺少pk_total参数',
  292. '113' => '签名不合法',
  293. '114' => '定时时间格式错误',
  294. '115' => '定时时间范围错误',
  295. '116' => '不支持HTTP',
  296. '201' => '无对应账户',
  297. '202' => '账户暂停',
  298. '203' => '账户删除',
  299. '204' => '账户IP没备案',
  300. '205' => '账户无余额',
  301. '206' => '密码错误',
  302. '301' => '无对应产品',
  303. '302' => '产品暂停',
  304. '303' => '产品删除',
  305. '304' => '产品不在服务时间',
  306. '305' => '无匹配通道',
  307. '306' => '通道暂停',
  308. '307' => '通道已删除',
  309. '308' => '通道不在服务时间',
  310. '309' => '未提供短信服务',
  311. '401' => '屏蔽词',
  312. '500' => '查询间隔太短',
  313. '999' => '其他错误',
  314. ];
  315. $error = isset($array[$code]) ? $array[$code] : '短信发送失败';
  316. return $error;
  317. }
  318. public function whatsapp_cm(){
  319. $account_id = '657a5348-b28f-4736-8c76-6c47f4b20e4e';
  320. $daibi = '350448a7-e8bc-4310-8d5b-db3518a5d05e';
  321. $url = 'https://gw.cmtelecom.com/v1.0/message';
  322. $client = new \CMText\TextClient('your-api-key');
  323. echo json_encode(
  324. $client->SendMessage('Message_Text', 'CM.com', [ '15866999421' ], 'Your_Reference')
  325. );
  326. }
  327. public function whatapp(){
  328. //临时token
  329. $token = 'EAAGE5ozNog8BO8eXkmeAygGQqEBlIZCTwnPjnZAF7d0f1M5Q1t4IW3GGHAwceY8FR9vkCbZBRHlaMyhDPsFeVaZAFVCbolk4vKvJGMjeG6POOEmPilr5wRvNhjZAnTyYYLZBZBaKPC0mpgvzoVb4OjPA0fXnExlRfPZCg4tQAwxtkFk1UlQRuCchXbxXWDOxiZB05iadOSTf8leHmYeiTHe2hMvkZC4BkZBuIZCfmf1F3qafXZAsHw4uqFfiI';
  330. $token = 'EAAGE5ozNog8BO1ZCLYLW5b4Cl2CAu3YVMPV2jmuuoxxoFpkGmyxvMKZAMaVFTVZAVCFL4AH9MyYZCVezuPSgIxTMRMoZA1yFl5v3G7ZBcz0jXByGjajjWTyPaPnZBgeDrTDK0ZB2FS9aK9gXoftxNpBuklAWns0RAbnEE4aNOMzp2eel5JrkbBW0XFUZAghhzZB3fNnBI8OotMSZBN4NSZA0';
  331. //发送者
  332. $mobile_id = '279740441892291'; //test number :+1 555 609 4631, WhatsApp Business Account ID: 306946452494181
  333. $mobile_id = '308176785712131'; //Elin Dance Stuido:+65 8879 9689 , WhatsApp Business Account ID: 309484315581636
  334. $mobile_id = '337736419413019'; //Elin Dance Stuido 2:+65 8015 4154 , WhatsApp Business Account ID: 336509229537586
  335. //没用的东西
  336. $config_id = '321757761015767';
  337. //接收者
  338. $receive_mobile = '65' . '88799689';
  339. //$receive_mobile = '86' . '15866999421';
  340. //发送
  341. $url = 'https://graph.facebook.com/v19.0/'.$mobile_id.'/messages';
  342. $header = [
  343. 'Authorization: Bearer ' . $token,
  344. 'Content-Type: application/json',
  345. ];
  346. $body = [
  347. 'messaging_product' => 'whatsapp',
  348. 'recipient_type' => 'individual',
  349. 'to' => $receive_mobile,
  350. 'type' => 'template',
  351. 'template' => [
  352. // 'name' => 'the_class_will_start_tomorrow',
  353. 'name' => 'package_expiration_reminder',
  354. 'language' => [
  355. // 'code' => 'zh_CN',
  356. 'code' => 'en_US'
  357. ],
  358. 'components' => [
  359. [
  360. 'type' => 'body',
  361. 'parameters' => [
  362. [
  363. 'type' => 'text',
  364. 'text' => '张三',
  365. ],
  366. [
  367. 'type' => 'text',
  368. 'text' => '瑜伽课',
  369. ],
  370. [
  371. 'type' => 'text',
  372. 'text' => '2024-05-10 12:30',
  373. ],
  374. ],
  375. ]
  376. ],
  377. ],
  378. ];
  379. $body = json_encode($body);
  380. $rs = curl_post($url,$body,$header);
  381. dump($rs);
  382. }
  383. /*
  384. 套餐到期提醒
  385. Package expiration reminder
  386. Hi,{{1}},您购买的套餐{{2}}将于{{3}}过期,建议您在过期内使用完毕!
  387. Hi, {{1}}, the package {{2}} you purchased will expire on {{3}}. We recommend that you use it up within the expiration date!
  388. */
  389. }