Demo.php 3.5 KB

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