Demo.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 test1(){
  39. $SnSclient = new SnsClient([
  40. 'profile' => 'default',
  41. 'region' => 'us-east-1',
  42. 'version' => '2010-03-31'
  43. ]);
  44. $subscription_token = 'arn:aws:sns:us-east-1:111122223333:MyTopic:123456-abcd-12ab-1234-12ba3dc1234a';
  45. $topic = 'arn:aws:sns:us-east-1:111122223333:MyTopic';
  46. try {
  47. $result = $SnSclient->confirmSubscription([
  48. 'Token' => $subscription_token,
  49. 'TopicArn' => $topic,
  50. ]);
  51. var_dump($result);
  52. } catch (AwsException $e) {
  53. // output error message if fails
  54. error_log($e->getMessage());
  55. }
  56. }
  57. public function test(){
  58. $out_trade_no = createUniqueNo('Test');
  59. $money = '1';
  60. $notifyurl = config('notify_cdnurl');
  61. $rs = $this->hitpay_payment($out_trade_no,$money,$notifyurl);
  62. dump($rs);
  63. //payorder 保存 $rs['id'] 为 payment_request_id
  64. }
  65. public function hitpay_payment($out_trade_no,$money,$notifyurl)
  66. {
  67. $return = [
  68. 'status' => false,
  69. 'msg' => '',
  70. 'url' => '',
  71. 'id' => 0,
  72. ];
  73. $apiKey = config('hitpay.apikey');
  74. try {
  75. $hitPayClient = new \HitPay\Client($apiKey, true);
  76. $request = new \HitPay\Request\CreatePayment();
  77. $request->setAmount($money)
  78. ->setCurrency('SGD')
  79. ->setPaymentMethods(['paynow_online','card'])
  80. ->setPurpose('Elin Dance Studio')
  81. ->setWebhook($notifyurl)
  82. ->setReferenceNumber($out_trade_no);
  83. $result = $hitPayClient->createPayment($request);
  84. $return['status'] = true;
  85. $return['url'] = $result->getUrl();
  86. $return['id'] = $result->getId();
  87. //print_r($result);
  88. /*$data = $hitPayClient->getPaymentStatus($result->getId());
  89. dump($data);
  90. dump($data->status);*/
  91. /*$data = $hitPayClient->deletePaymentRequest($data->getId());
  92. print_r($data);*/
  93. } catch (\Exception $e) {
  94. $return['msg'] = $e->getMessage();
  95. }
  96. return $return;
  97. }
  98. }