|
@@ -15,9 +15,9 @@ class Demo extends Api
|
|
|
//如果接口已经设置无需登录,那也就无需鉴权了
|
|
|
//
|
|
|
// 无需登录的接口,*表示全部
|
|
|
- protected $noNeedLogin = ['test', 'test1'];
|
|
|
+ protected $noNeedLogin = ['*'];
|
|
|
// 无需鉴权的接口,*表示全部
|
|
|
- protected $noNeedRight = ['test2'];
|
|
|
+ protected $noNeedRight = ['*'];
|
|
|
|
|
|
/**
|
|
|
* 测试方法
|
|
@@ -38,73 +38,86 @@ class Demo extends Api
|
|
|
'msg':'返回成功'
|
|
|
})
|
|
|
*/
|
|
|
- public function test()
|
|
|
+ public function test(){
|
|
|
+ $out_trade_no = createUniqueNo('Test');
|
|
|
+ $money = '0.3';
|
|
|
+ $notifyurl = config('notify_cdnurl');
|
|
|
+ $rs = $this->hitpay_payment($out_trade_no,$money,$notifyurl);
|
|
|
+ dump($rs);
|
|
|
+
|
|
|
+ //payorder 保存 $rs['id'] 为 payment_request_id
|
|
|
+ }
|
|
|
+
|
|
|
+ public function hitpay_payment($out_trade_no,$money,$notifyurl)
|
|
|
{
|
|
|
- $apiKey = '096a06e94fb1e0a8b015485bb76ef5dd63c167679297e07331a687327bd8b12e';
|
|
|
- $salt = 'LNrFYxOiGhtdHAuJiqqy3wOl1nVwyJn5dfOYkLquFx8j2J6bm2nsplTnpkYuKyo5';
|
|
|
+ $return = [
|
|
|
+ 'status' => false,
|
|
|
+ 'msg' => '',
|
|
|
+ 'url' => '',
|
|
|
+ 'id' => 0,
|
|
|
+ ];
|
|
|
|
|
|
- $hitPayClient = new \HitPay\Client($apiKey, false);
|
|
|
+ $apiKey = config('hitpay.apikey');
|
|
|
|
|
|
try {
|
|
|
+ $hitPayClient = new \HitPay\Client($apiKey, true);
|
|
|
+
|
|
|
$request = new \HitPay\Request\CreatePayment();
|
|
|
|
|
|
- $request->setAmount(66)
|
|
|
- ->setCurrency('SGD');
|
|
|
+ $request->setAmount($money)
|
|
|
+ ->setCurrency('SGD')
|
|
|
+ ->setWebhook($notifyurl)
|
|
|
+ ->setReferenceNumber($out_trade_no);
|
|
|
+
|
|
|
$result = $hitPayClient->createPayment($request);
|
|
|
|
|
|
- print_r($result);
|
|
|
+ $return['status'] = true;
|
|
|
+ $return['url'] = $result->getUrl();
|
|
|
+ $return['id'] = $result->getId();
|
|
|
+
|
|
|
+
|
|
|
+ //print_r($result);
|
|
|
|
|
|
$data = $hitPayClient->getPaymentStatus($result->getId());
|
|
|
- print_r($data);
|
|
|
+ dump($data);
|
|
|
+ dump($data->status);
|
|
|
+
|
|
|
+ /*$data = $hitPayClient->deletePaymentRequest($data->getId());
|
|
|
+ print_r($data);*/
|
|
|
|
|
|
- $data = $hitPayClient->deletePaymentRequest($data->getId());
|
|
|
- print_r($data);
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
- print_r($e->getMessage());
|
|
|
+ $return['msg'] = $e->getMessage();
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 无需登录的接口
|
|
|
- *
|
|
|
- */
|
|
|
- public function test1()
|
|
|
- {
|
|
|
- $curl = curl_init();
|
|
|
-
|
|
|
- curl_setopt_array($curl, [
|
|
|
- CURLOPT_URL => "https://api.sandbox.hit-pay.com/v1/orders",
|
|
|
- CURLOPT_RETURNTRANSFER => true,
|
|
|
- CURLOPT_ENCODING => "",
|
|
|
- CURLOPT_MAXREDIRS => 10,
|
|
|
- CURLOPT_TIMEOUT => 30,
|
|
|
- CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
|
- CURLOPT_CUSTOMREQUEST => "GET",
|
|
|
- CURLOPT_HTTPHEADER => [
|
|
|
- "X-BUSINESS-API-KEY: <096a06e94fb1e0a8b015485bb76ef5dd63c167679297e07331a687327bd8b12e>"
|
|
|
- ],
|
|
|
- ]);
|
|
|
-
|
|
|
- $response = curl_exec($curl);
|
|
|
- $err = curl_error($curl);
|
|
|
-
|
|
|
- curl_close($curl);
|
|
|
-
|
|
|
- if ($err) {
|
|
|
- echo "cURL Error #:" . $err;
|
|
|
- } else {
|
|
|
- echo $response;
|
|
|
- }
|
|
|
+ return $return;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 需要登录的接口
|
|
|
*
|
|
|
*/
|
|
|
public function test2()
|
|
|
{
|
|
|
- $this->success('返回成功', ['action' => 'test2']);
|
|
|
+ $url = 'https://api.hit-pay.com/v1/payment-requests';
|
|
|
+ $data = [
|
|
|
+ 'amount' => 1,
|
|
|
+ //'payment_method' => ['paynow_online', 'card', 'wechat', 'alipay', 'grabpay', 'fave_duit', 'shopback', 'atome'],
|
|
|
+ 'currency' => 'SGD',
|
|
|
+ //'webhook' => '',
|
|
|
+ ];
|
|
|
+
|
|
|
+ $header = array(
|
|
|
+ 'X-BUSINESS-API-KEY' => '096a06e94fb1e0a8b015485bb76ef5dd63c167679297e07331a687327bd8b12e',
|
|
|
+ 'Content-Type' => 'application/x-www-form-urlencoded',
|
|
|
+ 'X-Requested-With' => 'XMLHttpRequest'
|
|
|
+ );
|
|
|
+
|
|
|
+ $rs = curl_post($url,$data,$header);
|
|
|
+ dump($rs);
|
|
|
}
|
|
|
|
|
|
/**
|