Demo.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. require_once '../vendor/autoload.php';
  5. /**
  6. * 示例接口
  7. */
  8. class Demo extends Api
  9. {
  10. //如果$noNeedLogin为空表示所有接口都需要登录才能请求
  11. //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
  12. //如果接口已经设置无需登录,那也就无需鉴权了
  13. //
  14. // 无需登录的接口,*表示全部
  15. protected $noNeedLogin = ['test', 'test1'];
  16. // 无需鉴权的接口,*表示全部
  17. protected $noNeedRight = ['test2'];
  18. /**
  19. * 测试方法
  20. *
  21. * @ApiTitle (测试名称)
  22. * @ApiSummary (测试描述信息)
  23. * @ApiMethod (POST)
  24. * @ApiRoute (/api/demo/test/id/{id}/name/{name})
  25. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  26. * @ApiParams (name="id", type="integer", required=true, description="会员ID")
  27. * @ApiParams (name="name", type="string", required=true, description="用户名")
  28. * @ApiParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
  29. * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  30. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  31. * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
  32. * @ApiReturn ({
  33. 'code':'1',
  34. 'msg':'返回成功'
  35. })
  36. */
  37. public function test()
  38. {
  39. $apiKey = '096a06e94fb1e0a8b015485bb76ef5dd63c167679297e07331a687327bd8b12e';
  40. $salt = 'LNrFYxOiGhtdHAuJiqqy3wOl1nVwyJn5dfOYkLquFx8j2J6bm2nsplTnpkYuKyo5';
  41. $hitPayClient = new \HitPay\Client($apiKey, false);
  42. try {
  43. $request = new \HitPay\Request\CreatePayment();
  44. $request->setAmount(66)
  45. ->setCurrency('SGD');
  46. $result = $hitPayClient->createPayment($request);
  47. print_r($result);
  48. $data = $hitPayClient->getPaymentStatus($result->getId());
  49. print_r($data);
  50. $data = $hitPayClient->deletePaymentRequest($data->getId());
  51. print_r($data);
  52. } catch (\Exception $e) {
  53. print_r($e->getMessage());
  54. }
  55. }
  56. /**
  57. * 无需登录的接口
  58. *
  59. */
  60. public function test1()
  61. {
  62. $this->success('返回成功', ['action' => 'test1']);
  63. }
  64. /**
  65. * 需要登录的接口
  66. *
  67. */
  68. public function test2()
  69. {
  70. $this->success('返回成功', ['action' => 'test2']);
  71. }
  72. /**
  73. * 需要登录且需要验证有相应组的权限
  74. *
  75. */
  76. public function test3()
  77. {
  78. $this->success('返回成功', ['action' => 'test3']);
  79. }
  80. }