| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace App\Services\Payment;
- use GuzzleHttp\Client;
- use GuzzleHttp\Exception\RequestException;
- use GuzzleHttp\Psr7\Response;
- use App\Services\BaseService;
- class SanJinService extends BaseService
- {
- // SanJin payment service methods would go here
- const REQUEST_URL = 'https://api.qbdf13.com/';
- const ALIPAY_TO_CARD = 'DF001'; // 支付宝转银行卡
- const ALIPAY_TO_ALIPAY = 'DF002'; // 支付宝转支付宝
- // 获取异步的通知地址
- public static function getNotifyUrl()
- {
- return 'https://botpc28.testx2.cc/';
- }
-
- /**
- * @description: 获取请求客户端
- * @return {*}
- */
- public static function getClient(): Client
- {
- return new Client([
- 'base_uri' => self::REQUEST_URL,
- 'timeout' => 5.0,
- ]);
- }
- /**
- * @description: 查询商户余额
- * @return {array}
- * {array.success - 是否成功 true|false}
- * {array.msg - 返回错误消息}
- * {array.code - 返回状态码:200成功,其他失败}
- * {array.timestamp - 时间戳 13位}
- * {array.data - 商户余额}
- */
- public static function findBalance()
- {
- $merchant_id = config('app.tree_payment_merchant_id');
- $secret = config('app.tree_payment_secret');
- $sign = md5($merchant_id . $secret);
- $data = [
- 'merchantNum' => $merchant_id,
- 'sign' => $sign,
- ];
- $client = self::getClient();
- $response = $client->get('api/findBalance', [
- 'query' => $data,
- ]);
- $body = $response->getBody();
- return json_decode($body->getContents(), true);
- }
-
- public static function pay($amount, $order_no, $notify_url, $return_url)
- {
- $data = [];
- $merchant_id = config('app.tree_payment_merchant_id');
- $secret = config('app.tree_payment_secret');
- $data['merchantNum'] = $merchant_id;
- $data['amount'] = $amount;
- $data['orderNo'] = $order_no;
- $data['notifyUrl'] = $notify_url;
- $data['returnUrl'] = $return_url;
- $signStr = $merchant_id . $order_no . $amount . $secret;
- $sign = md5($signStr);
- $data['sign'] = $sign;
- $client = self::getClient();
- $response = $client->post('api/pay', [
- 'json' => $data,
- 'headers' => [
- 'Content-Type' => 'application/json',
- ]
- ]);
- $body = $response->getBody();
- $result = json_decode($body->getContents(), true);
-
- return $result;
- }
- }
|