This commit is contained in:
2021-06-01 16:12:27 +08:00
parent 48ff267183
commit 2012bfc6b6
8 changed files with 225 additions and 6 deletions

13
Action/BaseAction.php Normal file
View File

@@ -0,0 +1,13 @@
<?php
namespace XuanChen\PingAnSdk\Action;
class BaseAction extends Init
{
public function index()
{
re
}
}

8
Action/Info.php Normal file
View File

@@ -0,0 +1,8 @@
<?php
namespace XuanChen\PingAnSdk\Action;
class Info extends Init
{
}

176
Action/Init.php Normal file
View File

@@ -0,0 +1,176 @@
<?php
namespace XuanChen\PingAnSdk\Action;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
class Init
{
protected $appId;
protected $appSecret;
protected $apiVersion = 'v2';
protected $params;
protected $sign;
protected $url;
public function __construct()
{
$this->appId = config('pingan.appId');
$this->appSecret = config('pingan.appSecret');
}
/**
* Notes: 设置数据
* @Author: 玄尘
* @Date : 2021/6/1 14:37
* @param $data
* @return $this
*/
public function setParams($data)
{
//判断是否有sign有的话是传来的值
if (isset($data['sign'])) {
$this->sign = $data['sign'];
} else {
$data = array_merge($data, [
'appId' => $this->appId,
'apiVersion' => $this->apiVersion,
'timestamp' => $this->getMillisecond(),
]);
}
$this->params = $data;
return $this;
}
/**
* Notes: 获取传入值
* @Author: 玄尘
* @Date : 2021/6/1 15:31
* @return mixed
*/
public function getParams()
{
$params = $this->params;
$params['sign'] = $this->getSign();
return $params;
}
/**
* Notes: 获取签名
* @Author: 玄尘
* @Date : 2021/6/1 14:32
*/
public function getSign()
{
$str = $this->getSignString();
return md5($str);
}
/**
* Notes: 检验
* @Author: 玄尘
* @Date : 2021/6/1 15:32
*/
public function checkSign()
{
$sign = $this->getSign();
if ($sign == $this->sign) {
return true;
}
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: 获取时间戳
* @Author: 玄尘
* @Date : 2021/6/1 14:32
* @return float
*/
private function getMillisecond()
{
[$msec, $sec] = explode(' ', microtime());
$msectime = (float) sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
$msectime = explode('.', $msectime);
return $msectime[0];
}
/**
* Notes: description
* @Author: 玄尘
* @Date : 2021/6/1 14:32
*/
public function getSignString()
{
$params = $this->params;
if (empty($params)) {
throw new \Exception('获取校验数据失败,缺少数据.');
}
if (isset($params['sign'])) {
unset($params['sign']);
}
ksort($params);
return http_build_query($params) . $this->appSecret;
}
/**
* 通用获取数据接口
* @param [type] $url 请求地址
* @param array $query 传递参数
* @param array $json 需要传的json数据
* @param string $method 方式
* @return array|mixed [type] [description]
*/
public function http($url, $query, $method = 'POST')
{
try {
$client = new Client();
$response = $client->request($method, $url, $query);
$body = $response->getBody();
$content = $body->getContents();
$result = json_decode($content, true);
if ($result['ret'] > 0) {
$retData = $result['msg'];
} else {
$retData = $result['data'];
}
return $retData;
} catch (RequestException $e) {
return ['ret' => '99999', $e->getMessage()];
}
}
}

8
Action/Sign.php Normal file
View File

@@ -0,0 +1,8 @@
<?php
namespace XuanChen\PingAnSdk\Action;
class Info extends Conr
{
}

View File

@@ -6,4 +6,8 @@ return [
* 平安洗车券
*/
'appId' => 122121,
'appSecret' => '122121',
'apiVersion' => 'v2',
];

View File

@@ -35,8 +35,7 @@ class Init
public function __construct()
{
$this->this_type = config('pingan.this_type');
$pingan = config('pingan.' . $this->this_type);
$appId = config('pingan.appId');
$this->baseUri = $pingan['Uri'];
$this->tokenUri = $pingan['tokenUri'];

View File

@@ -2,12 +2,19 @@
namespace XuanChen\PingAnSdk;
use Carbon\Carbon;
use XuanChen\PingAnSdk\Action\BaseAction;
/**
* 平安SDK
*/
class PingAn
{
/**
* Notes: 基础
* @Author: 玄尘
* @Date : 2021/6/1 15:44
*/
public function base()
{
return new BaseAction();
}
}

View File

@@ -16,6 +16,10 @@ class ServiceProvider extends LaravelServiceProvider
if ($this->app->runningInConsole()) {
$this->publishes([__DIR__ . '/../config/config.php' => config_path('pingan.php')]);
}
$this->app->bind('xuanchen.pingan_washcar', function ($app) {
return new PingAn();
});
}
/**