Demo.php 18 KB

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