阶段更新
This commit is contained in:
@@ -9,7 +9,7 @@ return [
|
||||
],
|
||||
'ysd' => [
|
||||
'pattern' => '/^YSD/',
|
||||
'model' => \XuanChen\Coupon\Action\UnionPayAction::class,
|
||||
'model' => \XuanChen\Coupon\Action\YsdAction::class,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon\Action;
|
||||
|
||||
use XuanChen\Coupon\Action\sinopec\ZhyCreate;
|
||||
use XuanChen\Coupon\Contracts\CouponContracts;
|
||||
|
||||
/**
|
||||
* Class SinopecAction 中石化控制器
|
||||
* @Author: 玄尘
|
||||
* @Date: 2020/9/23 15:14
|
||||
* @package XuanChen\Coupon\Action
|
||||
*/
|
||||
class SinopecAction extends Init implements CouponContracts
|
||||
{
|
||||
/**
|
||||
* Notes: 创建营销活动
|
||||
* @Author: 玄尘
|
||||
* @Date: 2020/9/23 16:01
|
||||
* @param array $data
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
$action = new ZhyCreate();
|
||||
$action->data = $data;
|
||||
|
||||
return $action->start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 发券接口
|
||||
* @Author: 玄尘
|
||||
* @Date: 2020/9/23 15:58
|
||||
*/
|
||||
function grant()
|
||||
{
|
||||
// TODO: Implement grant() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 查询接口
|
||||
* @Author: 玄尘
|
||||
* @Date: 2020/9/23 15:58
|
||||
* @return mixed|void
|
||||
*/
|
||||
function detail()
|
||||
{
|
||||
// TODO: Implement detail() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 作废接口
|
||||
* @Author: 玄尘
|
||||
* @Date: 2020/9/23 15:59
|
||||
*/
|
||||
function destroy()
|
||||
{
|
||||
// TODO: Implement destroy() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 核销接口
|
||||
* @Author: 玄尘
|
||||
* @Date: 2020/9/23 16:00
|
||||
* @return mixed|void
|
||||
*/
|
||||
function start()
|
||||
{
|
||||
// TODO: Implement start() method.
|
||||
}
|
||||
}
|
||||
@@ -1,205 +1,205 @@
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon\Action\pingan;
|
||||
|
||||
use App\Models\PinganToken;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use XuanChen\Coupon\Action\Init;
|
||||
|
||||
/**
|
||||
* 超市购物券
|
||||
*/
|
||||
class PingAnInit extends Init
|
||||
{
|
||||
|
||||
protected $this_type;
|
||||
|
||||
protected $baseUri;
|
||||
|
||||
protected $tokenUri;
|
||||
|
||||
protected $client_id;
|
||||
|
||||
protected $grant_type;
|
||||
|
||||
protected $client_secret;
|
||||
|
||||
protected $access_token;
|
||||
|
||||
protected $userName;
|
||||
|
||||
protected $error;
|
||||
|
||||
protected $aes_code; //aes 密钥
|
||||
|
||||
protected $log;//日志
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->this_type = config('pingan.this_type');
|
||||
$pingan = config('pingan.' . $this->this_type);
|
||||
|
||||
$this->baseUri = $pingan['Uri'];
|
||||
$this->tokenUri = $pingan['tokenUri'];
|
||||
$this->client_id = $pingan['client_id'];
|
||||
$this->grant_type = $pingan['grant_type'];
|
||||
$this->userName = $pingan['userName'];
|
||||
$this->client_secret = $pingan['client_secret'];
|
||||
$this->aes_code = $pingan['AES_CODE'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取access_token
|
||||
* @return void [type] [description]
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
//从数据库里找token
|
||||
$token = PinganToken::where('type', $this->this_type)->orderBy('id', 'desc')->first();
|
||||
|
||||
if ($token) {
|
||||
$access_token = $token->access_token;
|
||||
$expires_in = $token->expires_in;
|
||||
$get_token_time = $token->get_token_time;
|
||||
$diffMinutes = $get_token_time->diffInMinutes(now(), false);
|
||||
if ($diffMinutes < $expires_in) {
|
||||
$this->access_token = $access_token;
|
||||
} else {
|
||||
$this->getAjaxToken();
|
||||
}
|
||||
} else {
|
||||
$this->getAjaxToken();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取毫秒级别的时间戳
|
||||
*/
|
||||
public function getMsecTime()
|
||||
{
|
||||
[$msec, $sec] = explode(' ', microtime());
|
||||
$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
|
||||
$msectime = explode('.', $msectime);
|
||||
|
||||
return $msectime[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求平台 access_token
|
||||
* @return void [type] [description]
|
||||
*/
|
||||
public function getAjaxToken()
|
||||
{
|
||||
$params = [
|
||||
'client_id' => $this->client_id,
|
||||
'grant_type' => $this->grant_type,
|
||||
'client_secret' => $this->client_secret,
|
||||
];
|
||||
|
||||
try {
|
||||
$log = $this->createLog($this->tokenUri, 'POST', $params, 'pingan');
|
||||
|
||||
$client = new Client();
|
||||
$response = $client->request('POST', $this->tokenUri, [
|
||||
'form_params' => $params,
|
||||
]);
|
||||
$body = $response->getBody();
|
||||
$content = $body->getContents();
|
||||
$result = json_decode($content, true);
|
||||
|
||||
$this->updateLog($log, $result); //更新日志
|
||||
|
||||
if ($result['ret'] > 0) {
|
||||
$this->error = $result['msg'];
|
||||
} else {
|
||||
$data = $result['data'];
|
||||
PinganToken::create([
|
||||
'type' => $this->this_type,
|
||||
'access_token' => $data['access_token'],
|
||||
'expires_in' => $data['expires_in'],
|
||||
'get_token_time' => now(),
|
||||
]);
|
||||
$this->access_token = $data['access_token'];
|
||||
$this->error = '';
|
||||
}
|
||||
} catch (RequestException $e) {
|
||||
$this->error = $e->getMessage();
|
||||
$this->updateLog($log, [$this->error]); //更新日志
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用获取数据接口
|
||||
* @param [type] $url 请求地址
|
||||
* @param array $query 传递参数
|
||||
* @param array $json 需要传的json数据
|
||||
* @param string $method 方式
|
||||
* @return array|mixed [type] [description]
|
||||
*/
|
||||
public function getPingAnData($url, $query = [], $json = [], $method = 'POST')
|
||||
{
|
||||
$this->getToken();
|
||||
|
||||
if ($this->error) {
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
$postData = [
|
||||
'query' => array_merge([
|
||||
'access_token' => $this->access_token,
|
||||
'request_id' => $this->getMsecTime(),
|
||||
'userName' => $this->userName,
|
||||
], $query),
|
||||
'json' => $json,
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json;charset=utf-8',
|
||||
'accept' => 'application/json;charset=utf-8',
|
||||
],
|
||||
];
|
||||
|
||||
$log = $this->createLog($url, $method, $postData, 'pingan'); //日志
|
||||
|
||||
try {
|
||||
$client = new Client();
|
||||
$response = $client->request($method, $url, $postData);
|
||||
$body = $response->getBody();
|
||||
$content = $body->getContents();
|
||||
$result = json_decode($content, true);
|
||||
|
||||
if ($result['ret'] > 0) {
|
||||
$retData = $result['msg'];
|
||||
} else {
|
||||
$retData = $result['data'];
|
||||
}
|
||||
$this->updateLog($log, $retData);//更新日志
|
||||
|
||||
return $retData;
|
||||
} catch (RequestException $e) {
|
||||
$this->updateLog($log, [$e->getMessage()]);//更新日志
|
||||
|
||||
return ['ret' => '99999', $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//加密
|
||||
public function encrypt($str)
|
||||
{
|
||||
if (is_array($str)) {
|
||||
$str = json_encode($str);
|
||||
}
|
||||
$data = openssl_encrypt($str, 'aes-128-ecb', $this->aes_code, OPENSSL_RAW_DATA);
|
||||
|
||||
return base64_encode($data);
|
||||
}
|
||||
|
||||
//解密
|
||||
public function decrypt($str)
|
||||
{
|
||||
$encrypted = base64_decode($str);
|
||||
|
||||
return openssl_decrypt($encrypted, 'aes-128-ecb', $this->aes_code, OPENSSL_RAW_DATA);
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon\Action\pingan;
|
||||
|
||||
use App\Models\PinganToken;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use XuanChen\Coupon\Action\Init;
|
||||
|
||||
/**
|
||||
* 超市购物券
|
||||
*/
|
||||
class PingAnInit extends Init
|
||||
{
|
||||
|
||||
protected $this_type;
|
||||
|
||||
protected $baseUri;
|
||||
|
||||
protected $tokenUri;
|
||||
|
||||
protected $client_id;
|
||||
|
||||
protected $grant_type;
|
||||
|
||||
protected $client_secret;
|
||||
|
||||
protected $access_token;
|
||||
|
||||
protected $userName;
|
||||
|
||||
protected $error;
|
||||
|
||||
protected $aes_code; //aes 密钥
|
||||
|
||||
protected $log;//日志
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->this_type = config('pingan.this_type');
|
||||
$pingan = config('pingan.' . $this->this_type);
|
||||
|
||||
$this->baseUri = $pingan['Uri'];
|
||||
$this->tokenUri = $pingan['tokenUri'];
|
||||
$this->client_id = $pingan['client_id'];
|
||||
$this->grant_type = $pingan['grant_type'];
|
||||
$this->userName = $pingan['userName'];
|
||||
$this->client_secret = $pingan['client_secret'];
|
||||
$this->aes_code = $pingan['AES_CODE'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取access_token
|
||||
* @return void [type] [description]
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
//从数据库里找token
|
||||
$token = PinganToken::where('type', $this->this_type)->orderBy('id', 'desc')->first();
|
||||
|
||||
if ($token) {
|
||||
$access_token = $token->access_token;
|
||||
$expires_in = $token->expires_in;
|
||||
$get_token_time = $token->get_token_time;
|
||||
$diffMinutes = $get_token_time->diffInMinutes(now(), false);
|
||||
if ($diffMinutes < $expires_in) {
|
||||
$this->access_token = $access_token;
|
||||
} else {
|
||||
$this->getAjaxToken();
|
||||
}
|
||||
} else {
|
||||
$this->getAjaxToken();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取毫秒级别的时间戳
|
||||
*/
|
||||
public function getMsecTime()
|
||||
{
|
||||
[$msec, $sec] = explode(' ', microtime());
|
||||
$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
|
||||
$msectime = explode('.', $msectime);
|
||||
|
||||
return $msectime[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求平台 access_token
|
||||
* @return void [type] [description]
|
||||
*/
|
||||
public function getAjaxToken()
|
||||
{
|
||||
$params = [
|
||||
'client_id' => $this->client_id,
|
||||
'grant_type' => $this->grant_type,
|
||||
'client_secret' => $this->client_secret,
|
||||
];
|
||||
|
||||
try {
|
||||
$log = $this->createLog($this->tokenUri, 'POST', $params, 'pingan');
|
||||
|
||||
$client = new Client();
|
||||
$response = $client->request('POST', $this->tokenUri, [
|
||||
'form_params' => $params,
|
||||
]);
|
||||
$body = $response->getBody();
|
||||
$content = $body->getContents();
|
||||
$result = json_decode($content, true);
|
||||
|
||||
$this->updateLog($log, $result); //更新日志
|
||||
|
||||
if ($result['ret'] > 0) {
|
||||
$this->error = $result['msg'];
|
||||
} else {
|
||||
$data = $result['data'];
|
||||
PinganToken::create([
|
||||
'type' => $this->this_type,
|
||||
'access_token' => $data['access_token'],
|
||||
'expires_in' => $data['expires_in'],
|
||||
'get_token_time' => now(),
|
||||
]);
|
||||
$this->access_token = $data['access_token'];
|
||||
$this->error = '';
|
||||
}
|
||||
} catch (RequestException $e) {
|
||||
$this->error = $e->getMessage();
|
||||
$this->updateLog($log, [$this->error]); //更新日志
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用获取数据接口
|
||||
* @param [type] $url 请求地址
|
||||
* @param array $query 传递参数
|
||||
* @param array $json 需要传的json数据
|
||||
* @param string $method 方式
|
||||
* @return array|mixed [type] [description]
|
||||
*/
|
||||
public function getPingAnData($url, $query = [], $json = [], $method = 'POST')
|
||||
{
|
||||
$this->getToken();
|
||||
|
||||
if ($this->error) {
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
$postData = [
|
||||
'query' => array_merge([
|
||||
'access_token' => $this->access_token,
|
||||
'request_id' => $this->getMsecTime(),
|
||||
'userName' => $this->userName,
|
||||
], $query),
|
||||
'json' => $json,
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json;charset=utf-8',
|
||||
'accept' => 'application/json;charset=utf-8',
|
||||
],
|
||||
];
|
||||
|
||||
$log = $this->createLog($url, $method, $postData, 'pingan'); //日志
|
||||
|
||||
try {
|
||||
$client = new Client();
|
||||
$response = $client->request($method, $url, $postData);
|
||||
$body = $response->getBody();
|
||||
$content = $body->getContents();
|
||||
$result = json_decode($content, true);
|
||||
|
||||
if ($result['ret'] > 0) {
|
||||
$retData = $result['msg'];
|
||||
} else {
|
||||
$retData = $result['data'];
|
||||
}
|
||||
$this->updateLog($log, $retData);//更新日志
|
||||
|
||||
return $retData;
|
||||
} catch (RequestException $e) {
|
||||
$this->updateLog($log, [$e->getMessage()]);//更新日志
|
||||
|
||||
return ['ret' => '99999', $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
//加密
|
||||
public function encrypt($str)
|
||||
{
|
||||
if (is_array($str)) {
|
||||
$str = json_encode($str);
|
||||
}
|
||||
$data = openssl_encrypt($str, 'aes-128-ecb', $this->aes_code, OPENSSL_RAW_DATA);
|
||||
|
||||
return base64_encode($data);
|
||||
}
|
||||
|
||||
//解密
|
||||
public function decrypt($str)
|
||||
{
|
||||
$encrypted = base64_decode($str);
|
||||
|
||||
return openssl_decrypt($encrypted, 'aes-128-ecb', $this->aes_code, OPENSSL_RAW_DATA);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon\Action\sinopec;
|
||||
|
||||
use XuanChen\Coupon\Contracts\CheckCouponContracts;
|
||||
|
||||
class ZhyCreate implements CheckCouponContracts
|
||||
{
|
||||
public $data;
|
||||
|
||||
public function start()
|
||||
{
|
||||
|
||||
try {
|
||||
[
|
||||
"cooperativeMerchant" => "",
|
||||
"eletronAndRule" => [
|
||||
[
|
||||
"entryMethod" => "01",
|
||||
"marketCode" => "20191213154203514",
|
||||
"marketRuleNumber" => "001",
|
||||
"perVoucherNumber" => "1",
|
||||
"planVoucherNumber" => "10",
|
||||
"queryCreateTime" => "2019-11-11 18=> 39=> 49",
|
||||
"similarStack" => "Y",
|
||||
"voucherEndTime" => "2019-12-15",
|
||||
"voucher_ruleCode" => "$01-VC-1573468710381900",
|
||||
"voucherRuleName" => "ceshi2",
|
||||
"voucherSource" => "S01",
|
||||
"voucherStartTime" => "2019-12-13",
|
||||
"voucherStartTime_type" => "VOUCHER_START_TIME_TYPE_ABSOLUTE_EFFECTIVE_TIME"
|
||||
]
|
||||
],
|
||||
"limitFrequency" => "",
|
||||
"mabIsRefund" => "",
|
||||
"marketCode" => "20191213154203514",
|
||||
"marketExEndTime" => "2019-12-15 00=> 00=> 00",
|
||||
"marketExStartTime" => "2019-12-13 00=> 00=> 00",
|
||||
"marketHierarchy" => "3311",
|
||||
"marketName" => "行为推送活动-3",
|
||||
"marketProvince" => "51",
|
||||
"marketReleaseSys" => "VOUCHER_PUBLISH_TYPE_APPLET",
|
||||
"marketStatus" => "MARKET_ACTIVITY_STATE_TAKE_EFFECT",
|
||||
"promotionCalculation" => "PROMOTION_TYPE_MEMBER_BEHAVIOR",
|
||||
"rule" => [
|
||||
[
|
||||
"cashValue" => "100",
|
||||
"channel" => "C01,C02,C03,C05",
|
||||
"fullType" => "",
|
||||
"marketCode" => "20191213154203514",
|
||||
"perVoucherNumber" => "1",
|
||||
"planVoucherNumber" => "10",
|
||||
"ruleCode" => "$01-VC-1573468710381900",
|
||||
"ruleDetail" => "123123",
|
||||
"ruleName" => "ceshi2",
|
||||
"voucherType" => "C01"
|
||||
]
|
||||
],
|
||||
"tradLimit" => [
|
||||
[
|
||||
"endValue" => "",
|
||||
"fixed" => "",
|
||||
"marketCode" => "20191213154203514",
|
||||
"marketRuleName" => "001",
|
||||
"marketRuleNumber" => "001",
|
||||
"memLevel" => "",
|
||||
"operator" => "",
|
||||
"startValue" => "",
|
||||
"tradingUnit" => "",
|
||||
"transactionType" => ""
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon\Action\sinopec;
|
||||
|
||||
use XuanChen\Coupon\Contracts\CheckCouponContracts;
|
||||
|
||||
class ZhyQuery implements CheckCouponContracts
|
||||
{
|
||||
public $data;
|
||||
|
||||
public function start()
|
||||
{
|
||||
|
||||
try {
|
||||
[
|
||||
"cooperativeMerchant" => "",
|
||||
"eletronAndRule" => [
|
||||
[
|
||||
"entryMethod" => "01",
|
||||
"marketCode" => "20191213154203514",
|
||||
"marketRuleNumber" => "001",
|
||||
"perVoucherNumber" => "1",
|
||||
"planVoucherNumber" => "10",
|
||||
"queryCreateTime" => "2019-11-11 18=> 39=> 49",
|
||||
"similarStack" => "Y",
|
||||
"voucherEndTime" => "2019-12-15",
|
||||
"voucher_ruleCode" => "$01-VC-1573468710381900",
|
||||
"voucherRuleName" => "ceshi2",
|
||||
"voucherSource" => "S01",
|
||||
"voucherStartTime" => "2019-12-13",
|
||||
"voucherStartTime_type" => "VOUCHER_START_TIME_TYPE_ABSOLUTE_EFFECTIVE_TIME"
|
||||
]
|
||||
],
|
||||
"limitFrequency" => "",
|
||||
"mabIsRefund" => "",
|
||||
"marketCode" => "20191213154203514",
|
||||
"marketExEndTime" => "2019-12-15 00=> 00=> 00",
|
||||
"marketExStartTime" => "2019-12-13 00=> 00=> 00",
|
||||
"marketHierarchy" => "3311",
|
||||
"marketName" => "行为推送活动-3",
|
||||
"marketProvince" => "51",
|
||||
"marketReleaseSys" => "VOUCHER_PUBLISH_TYPE_APPLET",
|
||||
"marketStatus" => "MARKET_ACTIVITY_STATE_TAKE_EFFECT",
|
||||
"promotionCalculation" => "PROMOTION_TYPE_MEMBER_BEHAVIOR",
|
||||
"rule" => [
|
||||
[
|
||||
"cashValue" => "100",
|
||||
"channel" => "C01,C02,C03,C05",
|
||||
"fullType" => "",
|
||||
"marketCode" => "20191213154203514",
|
||||
"perVoucherNumber" => "1",
|
||||
"planVoucherNumber" => "10",
|
||||
"ruleCode" => "$01-VC-1573468710381900",
|
||||
"ruleDetail" => "123123",
|
||||
"ruleName" => "ceshi2",
|
||||
"voucherType" => "C01"
|
||||
]
|
||||
],
|
||||
"tradLimit" => [
|
||||
[
|
||||
"endValue" => "",
|
||||
"fixed" => "",
|
||||
"marketCode" => "20191213154203514",
|
||||
"marketRuleName" => "001",
|
||||
"marketRuleNumber" => "001",
|
||||
"memLevel" => "",
|
||||
"operator" => "",
|
||||
"startValue" => "",
|
||||
"tradingUnit" => "",
|
||||
"transactionType" => ""
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,144 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* 自有卡券系统
|
||||
*/
|
||||
class Coupon
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 发券接口
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/28 15:07
|
||||
* @param $activityId 活动编号
|
||||
* @param $outletId 网点编号
|
||||
* @param $mobile 手机号
|
||||
*/
|
||||
public static function Grant($activityId, $outletId, $mobile)
|
||||
{
|
||||
$model = config('xuanchen_coupon.rules.ysd.model');
|
||||
|
||||
return (new $model)->setActivityId($activityId)
|
||||
->setOutletId($outletId)
|
||||
->setMobile($mobile)
|
||||
->grant();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 查询接口
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/7/21 11:58
|
||||
* @param $redemptionCode
|
||||
*/
|
||||
public static function Query($redemptionCode, $outletId)
|
||||
{
|
||||
if (!$redemptionCode) {
|
||||
return '查询失败,未获取到券码';
|
||||
}
|
||||
|
||||
$model = self::getModelByCode($redemptionCode);
|
||||
if (is_string($model)) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return $model->setCode($redemptionCode)
|
||||
->setOutletId($outletId)
|
||||
->detail();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 卡券作废
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/9/2 16:54
|
||||
* @param $redemptionCode
|
||||
* @param $outletId
|
||||
* @return string
|
||||
*/
|
||||
public static function Destroy($redemptionCode, $outletId)
|
||||
{
|
||||
try {
|
||||
$model = self::getModelByCode($redemptionCode);
|
||||
if (is_string($model)) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return $model->setCode($redemptionCode)
|
||||
->setOutletId($outletId)
|
||||
->destroy();
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 根据券码 获取class
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/7/21 12:00
|
||||
* @param $code
|
||||
* @return string
|
||||
*/
|
||||
public static function getModelByCode($code)
|
||||
{
|
||||
$rules = config('xuanchen_coupon.rules');
|
||||
if (!$rules) {
|
||||
return '系统出错,未找到配置文件';
|
||||
}
|
||||
|
||||
$model = '';
|
||||
foreach ($rules as $rule) {
|
||||
if (preg_match($rule['pattern'], $code, $matches)) {
|
||||
$model = $rule['model'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$model) {
|
||||
throw new \Exception('卡券核销失败。未查到卡券所属');
|
||||
}
|
||||
|
||||
return new $model;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: description
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/8/21 13:33
|
||||
* @param \App\Models\User $user 渠道
|
||||
* @param string $redemptionCode 要核销的券码
|
||||
* @param float $total 订单金额
|
||||
* @param string $outletId 网点id
|
||||
* @param string $orderid 订单id
|
||||
* @return string
|
||||
*/
|
||||
public static function Redemption(User $user, string $redemptionCode, float $total, string $outletId, string $orderid = '')
|
||||
{
|
||||
|
||||
try {
|
||||
$model = self::getModelByCode($redemptionCode);
|
||||
if (is_string($model)) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return $model->setUser($user)
|
||||
->setCode($redemptionCode)
|
||||
->setTotal($total)
|
||||
->setOutletId($outletId)
|
||||
->setOrderId($orderid)
|
||||
->start();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* 自有卡券系统
|
||||
*/
|
||||
class Coupon
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 发券接口
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/28 15:07
|
||||
* @param $activityId 活动编号
|
||||
* @param $outletId 网点编号
|
||||
* @param $mobile 手机号
|
||||
*/
|
||||
public static function Grant($activityId, $outletId, $mobile)
|
||||
{
|
||||
$model = config('xuanchen_coupon.rules.ysd.model');
|
||||
|
||||
return (new $model)->setActivityId($activityId)
|
||||
->setOutletId($outletId)
|
||||
->setMobile($mobile)
|
||||
->grant();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 查询接口
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/7/21 11:58
|
||||
* @param $redemptionCode
|
||||
*/
|
||||
public static function Query($redemptionCode, $outletId)
|
||||
{
|
||||
if (!$redemptionCode) {
|
||||
return '查询失败,未获取到券码';
|
||||
}
|
||||
|
||||
$model = self::getModelByCode($redemptionCode);
|
||||
if (is_string($model)) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return $model->setCode($redemptionCode)
|
||||
->setOutletId($outletId)
|
||||
->detail();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 卡券作废
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/9/2 16:54
|
||||
* @param $redemptionCode
|
||||
* @param $outletId
|
||||
* @return string
|
||||
*/
|
||||
public static function Destroy($redemptionCode, $outletId)
|
||||
{
|
||||
try {
|
||||
$model = self::getModelByCode($redemptionCode);
|
||||
if (is_string($model)) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return $model->setCode($redemptionCode)
|
||||
->setOutletId($outletId)
|
||||
->destroy();
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 根据券码 获取class
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/7/21 12:00
|
||||
* @param $code
|
||||
* @return string
|
||||
*/
|
||||
public static function getModelByCode($code)
|
||||
{
|
||||
$rules = config('xuanchen_coupon.rules');
|
||||
if (!$rules) {
|
||||
return '系统出错,未找到配置文件';
|
||||
}
|
||||
|
||||
$model = '';
|
||||
foreach ($rules as $rule) {
|
||||
if (preg_match($rule['pattern'], $code, $matches)) {
|
||||
$model = $rule['model'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$model) {
|
||||
throw new \Exception('卡券核销失败。未查到卡券所属');
|
||||
}
|
||||
|
||||
return new $model;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: description
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/8/21 13:33
|
||||
* @param \App\Models\User $user 渠道
|
||||
* @param string $redemptionCode 要核销的券码
|
||||
* @param float $total 订单金额
|
||||
* @param string $outletId 网点id
|
||||
* @param string $orderid 订单id
|
||||
* @return string
|
||||
*/
|
||||
public static function Redemption(User $user, string $redemptionCode, float $total, string $outletId, string $orderid = '')
|
||||
{
|
||||
|
||||
try {
|
||||
$model = self::getModelByCode($redemptionCode);
|
||||
if (is_string($model)) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return $model->setUser($user)
|
||||
->setCode($redemptionCode)
|
||||
->setTotal($total)
|
||||
->setOutletId($outletId)
|
||||
->setOrderId($orderid)
|
||||
->start();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
32
packages/coupon/src/CouponServiceProvider.php
Normal file
32
packages/coupon/src/CouponServiceProvider.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class CouponServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Register services.
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
dd(1);
|
||||
if ($this->app->runningInConsole()) {
|
||||
$this->publishes([__DIR__ . '/../config/xuanchen_coupon.php' => config_path('xuanchen_coupon.php')]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap services.
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->mergeConfigFrom(__DIR__ . '/../config/xuanchen_coupon.php', 'xuanchen_coupon');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon\Traits;
|
||||
|
||||
use App\Models\Log as LogModel;
|
||||
|
||||
trait Log
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 插入日志
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/30 10:29
|
||||
* @param $url
|
||||
* @param $method
|
||||
* @param $params
|
||||
* @param string $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function createLog($url, $method, $params, $type = 'pingan')
|
||||
{
|
||||
$data = [
|
||||
'path' => $url,
|
||||
'method' => $method,
|
||||
'type' => $type,
|
||||
'in_source' => $params,
|
||||
];
|
||||
|
||||
$info = LogModel::create($data);
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 更新日志
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/30 10:29
|
||||
* @param $log
|
||||
* @param $params
|
||||
*/
|
||||
public static function updateLog($log, $params)
|
||||
{
|
||||
$log->out_source = $params;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace XuanChen\Coupon\Traits;
|
||||
|
||||
use App\Models\Log as LogModel;
|
||||
|
||||
trait Log
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 插入日志
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/30 10:29
|
||||
* @param $url
|
||||
* @param $method
|
||||
* @param $params
|
||||
* @param string $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function createLog($url, $method, $params, $type = 'pingan')
|
||||
{
|
||||
$data = [
|
||||
'path' => $url,
|
||||
'method' => $method,
|
||||
'type' => $type,
|
||||
'in_source' => $params,
|
||||
];
|
||||
|
||||
$info = LogModel::create($data);
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 更新日志
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/30 10:29
|
||||
* @param $log
|
||||
* @param $params
|
||||
*/
|
||||
public static function updateLog($log, $params)
|
||||
{
|
||||
$log->out_source = $params;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ return [
|
||||
],
|
||||
'ysd' => [
|
||||
'pattern' => '/^YSD/',
|
||||
'model' => \XuanChen\Coupon\Action\UnionPayAction::class,
|
||||
'model' => \XuanChen\Coupon\Action\SinopecAction::class,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
|
||||
namespace XuanChen\UnionPay\Action;
|
||||
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Init
|
||||
{
|
||||
public $params;
|
||||
public $sign;
|
||||
|
||||
/**
|
||||
* RSA验签
|
||||
@@ -14,15 +17,16 @@ class Init
|
||||
* @param $sign 要校对的的签名结果
|
||||
* return 验证结果
|
||||
*/
|
||||
public function rsaSign($params, $self = false)
|
||||
public function checkSign($self = false)
|
||||
{
|
||||
$sign = $params['sign'];
|
||||
unset($params['sign']);
|
||||
|
||||
$sign = $this->sign;
|
||||
$sign = base64_decode($sign);
|
||||
|
||||
$public_key = $this->getPublic($self);
|
||||
|
||||
$pub_key_id = openssl_get_publickey($public_key);
|
||||
|
||||
$signStr = $this->getSignString($params);
|
||||
$signStr = $this->getSignString($this->params);
|
||||
|
||||
if ($pub_key_id) {
|
||||
$result = (bool)openssl_verify($signStr, $sign, $pub_key_id);
|
||||
@@ -34,14 +38,36 @@ class Init
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 签名
|
||||
* @Author: 玄尘
|
||||
* @Date: 2020/9/29 9:56
|
||||
* @return string
|
||||
*/
|
||||
public function getSign()
|
||||
{
|
||||
$signStr = $this->getSignString();
|
||||
$private_key = $this->getPrivate();
|
||||
|
||||
$privKeyId = openssl_pkey_get_private($private_key);
|
||||
if (!$privKeyId) {
|
||||
return '私钥格式有误';
|
||||
}
|
||||
|
||||
openssl_sign($signStr, $signature, $privKeyId);
|
||||
openssl_free_key($privKeyId);
|
||||
|
||||
return base64_encode($signature);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取待签名字符串
|
||||
* @param array $params 参数数组
|
||||
* @return string
|
||||
*/
|
||||
public function getSignString($params)
|
||||
public function getSignString()
|
||||
{
|
||||
$params = array_filter($params);
|
||||
$params = array_filter($this->params);
|
||||
ksort($params);
|
||||
$signStr = http_build_query($params);
|
||||
return $signStr;
|
||||
@@ -51,6 +77,11 @@ class Init
|
||||
public function getPrivate()
|
||||
{
|
||||
$private = config('unionpay.check.self.private');
|
||||
|
||||
if (!file_exists($private)) {
|
||||
throw new \Exception('缺少私钥文件');
|
||||
}
|
||||
|
||||
return file_get_contents($private);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,20 @@
|
||||
namespace XuanChen\UnionPay;
|
||||
|
||||
use App\Models\User;
|
||||
use http\Env\Request;
|
||||
use XuanChen\UnionPay\Action\Init;
|
||||
|
||||
/**
|
||||
* 银联入口
|
||||
*/
|
||||
class UnionPay
|
||||
class UnionPay extends Init
|
||||
{
|
||||
|
||||
public function __construct($params, $sign = '')
|
||||
{
|
||||
$this->params = $params;
|
||||
$this->sign = $sign;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 查询接口
|
||||
* @Author: 玄尘
|
||||
@@ -126,24 +132,4 @@ class UnionPay
|
||||
|
||||
}
|
||||
|
||||
//验证签名
|
||||
public function checkSign($params)
|
||||
{
|
||||
$sign = $params['sign'];
|
||||
unset($params['sign']);
|
||||
|
||||
$signStr = $this->getSignString($params);
|
||||
|
||||
$private_key = $this->getPrivate();
|
||||
$privKeyId = openssl_pkey_get_private($private_key);
|
||||
if (!$privKeyId) {
|
||||
return '私钥格式有误';
|
||||
}
|
||||
|
||||
openssl_sign($signStr, $signature, $privKeyId, OPENSSL_ALGO_SHA1);
|
||||
openssl_free_key($privKeyId);
|
||||
|
||||
return bin2hex($signature);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user