Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 32f6391d1f | |||
| 25ff64defe |
@@ -6,8 +6,31 @@ return [
|
|||||||
* 平安洗车券
|
* 平安洗车券
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'appId' => 122121,
|
'this_type' => 'test',
|
||||||
'appSecret' => '122121',
|
/**
|
||||||
|
* 测试环境参数
|
||||||
|
*/
|
||||||
|
'test' => [
|
||||||
|
'client_id' => env('WASH_CAR_APPID', ''),//就是 appId
|
||||||
|
'client_secret' => env('WASH_CAR_SECRET', ''),// 就是 client_secret
|
||||||
'apiVersion' => 'v2',
|
'apiVersion' => 'v2',
|
||||||
|
'grant_type' => 'client_credentials',
|
||||||
|
'tokenUri' => 'https://open.cyzl.com/beta/api/auth/oauth/token',
|
||||||
|
'baseUri' => 'https://open.cyzl.com/beta/api',
|
||||||
|
'urlKey' => env('WASH_CAR_URLKEY', ''),//免登陆跳转
|
||||||
|
],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生产环境参数
|
||||||
|
*/
|
||||||
|
'dev' => [
|
||||||
|
'client_id' => env('WASH_CAR_APPID', ''),//就是 appId
|
||||||
|
'client_secret' => env('WASH_CAR_SECRET', ''),// 就是 client_secret
|
||||||
|
'apiVersion' => 'v2',
|
||||||
|
'grant_type' => 'client_credentials',
|
||||||
|
'tokenUri' => 'https://open.cyzl.com/api/auth/oauth/token',
|
||||||
|
'baseUri' => 'https://open.cyzl.com/api',
|
||||||
|
'urlKey' => env('WASH_CAR_URLKEY', ''),//免登陆跳转
|
||||||
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
51
src/Action/CouponAction.php
Normal file
51
src/Action/CouponAction.php
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace XuanChen\WashCar\Action;
|
||||||
|
|
||||||
|
class CouponAction extends Init
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 发券
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/4 14:26
|
||||||
|
*/
|
||||||
|
public function grant()
|
||||||
|
{
|
||||||
|
$url = $this->config['baseUri'] . '/v2/rights/coupon/getCoupon';
|
||||||
|
|
||||||
|
$res = $this->http($url, $this->params);
|
||||||
|
dd($res);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 查询
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/4 14:28
|
||||||
|
*/
|
||||||
|
public function query()
|
||||||
|
{
|
||||||
|
$url = $this->config['baseUri'] . '/v2/rights/coupon/getCouponStatus';
|
||||||
|
|
||||||
|
$this->http($url, $this->params);
|
||||||
|
|
||||||
|
return $this->getResponse();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 取消优惠券
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/4 14:29
|
||||||
|
*/
|
||||||
|
public function cancel()
|
||||||
|
{
|
||||||
|
$url = $this->config['baseUri'] . '/v2/rights/coupon/recedeCoupon';
|
||||||
|
|
||||||
|
$this->http($url, $this->params);
|
||||||
|
|
||||||
|
return $this->getResponse();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,26 +4,97 @@ namespace XuanChen\WashCar\Action;
|
|||||||
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\RequestException;
|
use GuzzleHttp\Exception\RequestException;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
class Init
|
class Init
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $appId;
|
/**
|
||||||
|
* @var 入参
|
||||||
protected $appSecret;
|
*/
|
||||||
|
|
||||||
protected $apiVersion = 'v2';
|
|
||||||
|
|
||||||
protected $params;
|
protected $params;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var 待校验的签名
|
||||||
|
*/
|
||||||
protected $sign;
|
protected $sign;
|
||||||
|
|
||||||
protected $url;
|
/**
|
||||||
|
* @var 环境
|
||||||
|
*/
|
||||||
|
protected $this_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var token
|
||||||
|
*/
|
||||||
|
protected $access_token;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @var 错误标识
|
||||||
|
*/
|
||||||
|
protected $error = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @var 错误原因
|
||||||
|
*/
|
||||||
|
protected $message;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->appId = config('pingan.appId');
|
$this->this_type = config('washcar.this_type');
|
||||||
$this->appSecret = config('pingan.appSecret');
|
$this->config = config('washcar.' . $this->this_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取access_token
|
||||||
|
* @return void [type] [description]
|
||||||
|
*/
|
||||||
|
public function getToken()
|
||||||
|
{
|
||||||
|
$this_type = $this->config['this_type'];
|
||||||
|
|
||||||
|
//从缓存里找token
|
||||||
|
$token = Cache::get('token_' . $this_type);
|
||||||
|
|
||||||
|
if ($token) {
|
||||||
|
$token = collect($token);
|
||||||
|
$this->access_token = $token->access_token;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->getAjaxToken();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求平台 access_token
|
||||||
|
* @return void [type] [description]
|
||||||
|
*/
|
||||||
|
public function getAjaxToken()
|
||||||
|
{
|
||||||
|
$params = [
|
||||||
|
'client_id' => $this->config['client_id'],
|
||||||
|
'grant_type' => $this->config['grant_type'],
|
||||||
|
'client_secret' => $this->config['client_secret'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$tokenUrl = $this->config['tokenUri'];
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->http($tokenUrl, $params, 'POST');
|
||||||
|
|
||||||
|
if ($this->error > 0) {
|
||||||
|
return new \Exception($this->message);
|
||||||
|
}
|
||||||
|
|
||||||
|
Cache::put('token_' . $this->grant_type, $this->data['expires_in']);
|
||||||
|
|
||||||
|
$this->access_token = $data['access_token'];
|
||||||
|
|
||||||
|
} catch (RequestException $e) {
|
||||||
|
$this->error = 9999;
|
||||||
|
$this->message = $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,8 +111,8 @@ class Init
|
|||||||
$this->sign = $data['sign'];
|
$this->sign = $data['sign'];
|
||||||
} else {
|
} else {
|
||||||
$data = array_merge($data, [
|
$data = array_merge($data, [
|
||||||
'appId' => $this->appId,
|
'appId' => $this->config['client_id'],
|
||||||
'apiVersion' => $this->apiVersion,
|
'apiVersion' => $this->config['apiVersion'],
|
||||||
'timestamp' => $this->getMillisecond(),
|
'timestamp' => $this->getMillisecond(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -92,20 +163,6 @@ class Init
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Notes: 封装跳转链接
|
|
||||||
* @Author: 玄尘
|
|
||||||
* @Date : 2021/6/1 15:25
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getUrl()
|
|
||||||
{
|
|
||||||
$params = $this->params;
|
|
||||||
$params['sign'] = $this->getSign();
|
|
||||||
|
|
||||||
return $this->url . http_build_query($this->params);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notes: 获取时间戳
|
* Notes: 获取时间戳
|
||||||
* @Author: 玄尘
|
* @Author: 玄尘
|
||||||
@@ -140,7 +197,7 @@ class Init
|
|||||||
|
|
||||||
ksort($params);
|
ksort($params);
|
||||||
|
|
||||||
return http_build_query($params) . $this->appSecret;
|
return http_build_query($params) . $this->config['client_secret'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -154,23 +211,47 @@ class Init
|
|||||||
public function http($url, $query, $method = 'POST')
|
public function http($url, $query, $method = 'POST')
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$headers = [
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
];
|
||||||
|
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
$response = $client->request($method, $url, $query);
|
$response = $client->request($method, $url, [
|
||||||
|
'json' => $query,
|
||||||
|
'headers' => $headers,
|
||||||
|
]);
|
||||||
|
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
$content = $body->getContents();
|
$content = $body->getContents();
|
||||||
$result = json_decode($content, true);
|
$result = json_decode($content, true);
|
||||||
|
|
||||||
if ($result['ret'] > 0) {
|
if ($result['ret'] > 0) {
|
||||||
$retData = $result['msg'];
|
$this->error = $result['ret'];
|
||||||
|
$this->message = $result['message'];
|
||||||
|
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
$retData = $result['data'];
|
$retData = $result['data'];
|
||||||
|
$this->data = $retData;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $retData;
|
|
||||||
} catch (RequestException $e) {
|
} catch (RequestException $e) {
|
||||||
|
|
||||||
return ['ret' => '99999', $e->getMessage()];
|
return ['ret' => '99999', $e->getMessage()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 返回
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/4 14:48
|
||||||
|
*/
|
||||||
|
public function getResponse()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'error' => $this->error,
|
||||||
|
'message' => $this->message,
|
||||||
|
'data' => $this->data,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
36
src/Action/UrlAction.php
Normal file
36
src/Action/UrlAction.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace XuanChen\WashCar\Action;
|
||||||
|
|
||||||
|
class UrlAction extends Init
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 跳转到下单url
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/4 14:11
|
||||||
|
*/
|
||||||
|
public function getOrderUrl()
|
||||||
|
{
|
||||||
|
$url = $this->config['baseUri'] . '/v2/h5/redirect/autoLogin/returnUrl';
|
||||||
|
|
||||||
|
$params = array_merge($this->params, [
|
||||||
|
'urlKey' => $this->config['urlKey'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->http($url, $params);
|
||||||
|
|
||||||
|
return $this->getResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Notes: 获取优惠券详情地址
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/4 14:11
|
||||||
|
*/
|
||||||
|
public function getCouponInfoUrl()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace XuanChen\WashCar;
|
|
||||||
|
|
||||||
use XuanChen\WashCar\Action\BaseAction;
|
|
||||||
|
|
||||||
class PingAn
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notes: 基础
|
|
||||||
* @Author: 玄尘
|
|
||||||
* @Date : 2021/6/1 15:44
|
|
||||||
*/
|
|
||||||
public function base()
|
|
||||||
{
|
|
||||||
return new BaseAction();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -17,8 +17,8 @@ class ServiceProvider extends LaravelServiceProvider
|
|||||||
$this->publishes([__DIR__ . '/../config/config.php' => config_path('pingan.php')]);
|
$this->publishes([__DIR__ . '/../config/config.php' => config_path('pingan.php')]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->app->bind('xuanchen.pingan_washcar', function ($app) {
|
$this->app->bind('xuanchen.washcar', function ($app) {
|
||||||
return new PingAn();
|
return new WashCar();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
42
src/WashCar.php
Normal file
42
src/WashCar.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace XuanChen\WashCar;
|
||||||
|
|
||||||
|
use XuanChen\WashCar\Action\BaseAction;
|
||||||
|
use XuanChen\WashCar\Action\UrlAction;
|
||||||
|
|
||||||
|
class WashCar
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 基础
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/1 15:44
|
||||||
|
*/
|
||||||
|
public function base()
|
||||||
|
{
|
||||||
|
return new BaseAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 获取url
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/4 11:34
|
||||||
|
* @return \XuanChen\WashCar\Action\UrlAction
|
||||||
|
*/
|
||||||
|
public function url()
|
||||||
|
{
|
||||||
|
return new UrlAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 优惠券
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/4 14:25
|
||||||
|
*/
|
||||||
|
public function coupon()
|
||||||
|
{
|
||||||
|
return new Coupon
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user