Demo.php 13 KB

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