4 Commits
1.0.2 ... 1.0.5

Author SHA1 Message Date
f49481ad29 修改字符串判断 2021-08-13 09:39:26 +08:00
3d867be82d 微调 2021-08-12 17:06:57 +08:00
a803fc2f1d 增加查询接口 2021-08-12 16:43:15 +08:00
32b76b30d9 调整日志 2021-07-23 14:32:06 +08:00
7 changed files with 111 additions and 39 deletions

View File

@@ -139,7 +139,7 @@ class Init
$result = (bool) openssl_verify($signStr, $sign, $pub_key_id, 'SHA256');
openssl_free_key($pub_key_id);
} else {
throw new \Exception('钥格式有误');
throw new \Exception('钥格式有误');
}
return $result;
@@ -156,8 +156,7 @@ class Init
{
$signStr = $this->getSignString();
$private_key = $this->getPrivate();
$privKeyId = openssl_get_privatekey($private_key);
$privKeyId = openssl_get_privatekey($private_key);
if (!$privKeyId) {
throw new \Exception('私钥格式有误');
@@ -301,7 +300,6 @@ class Init
}
$client = new Client();
try {
$response = $client->request('POST', $url, [
'form_params' => $paramArray,
@@ -312,26 +310,27 @@ class Init
if ($response->getStatusCode() == 200) {
$body = $response->getBody();
$content = str_replace(["\r\n", "\n", "\r", '/n', "\\n",], '&', $body->getContents());
parse_str($content, $data);
$this->data = $data;
if ($data['transRet'] != 'SUCCESS') {
$this->code = false;
$this->message = $data['resultDis'];
if (isset($data['queryResult']) && $data['queryResult'] != 'SUCCESS') {
throw new \Exception('返回的数据错误');
}
if (isset($data['transRet']) && $data['transRet'] != 'SUCCESS') {
throw new \Exception($data['resultDis']);
}
$this->code = true;
} else {
$this->code = false;
$this->message = '接口错误 Post';
throw new \Exception('未正常返回数据');
}
} catch (\Exception $exception) {
$this->code = false;
$this->message = '接口错误 Post' . $exception->getMessage();
$this->message = '接口错误 ' . $exception->getMessage();
}
}

View File

@@ -13,6 +13,28 @@ class Query extends Init
public function start()
{
$this->setIsLower(false);
$this->addData();
$this->setSignData();
$url = config('wounicom.uri.unicom.query');
$this->sendPost($this->params, $url);
return $this->respond();
}
public function addData()
{
$order = $this->params;
$data = [
'merNo' => $this->merNo,
'orderNo' => $order->orderid,
'orderDate' => $order->created_at->format('Ymd'),
'charSet' => 'UTF-8',
'signType' => config('wounicom.signType'),
];
$this->params = $data;
}

View File

@@ -35,7 +35,7 @@ class Refund extends Init
'orderDate' => $order->created_at->format('Ymd'),
'payJournl' => $order->payment->out_trade_no,
'merReqTime' => Carbon::now()->format('YmdHis'),
'amount' => -1,
'amount' => $order->payment->amount * 100,
'reason' => '退款',
'signType' => 'RSA_SHA256',
];

View File

@@ -17,6 +17,7 @@ class Sign extends Init
// $signMsg = str_replace('\\', '', $signMsg);
$signMsg = str_replace(' ', '+', $signMsg);
$this->sign = $signMsg;
info($this->sign);
return $this->checkSign();

17
src/Model/Wounicom.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
namespace XuanChen\WoUnicom\Model;
use Illuminate\Database\Eloquent\Model;
class Wounicom extends Model
{
protected $guarded = [];
public $casts = [
'source' => 'json',
'outsource' => 'json',
];
}

46
src/Traits/Log.php Normal file
View File

@@ -0,0 +1,46 @@
<?php
namespace XuanChen\WoUnicom\Traits;
use XuanChen\WoUnicom\Model\Wounicom as LogModel;
trait Log
{
public $log;
/**
* Notes: 输入日志
* @Author: 玄尘
* @Date : 2021/5/11 15:58
* @param $data
*/
public function createLog($data, $str)
{
return $this->log = LogModel::create([
'orderId' => $data['orderid'],
'payFloodId' => $data['payfloodid'],
'payResult' => $data['payresult'],
'payBalance' => $data['paybalance'],
'paymentBalanceDetail' => $data['paymentbalancedetail'],
'respTime' => $data['resptime'],
'source' => [
'data' => $data,
'check_sign' => $str,
],
]);
}
/**
* Notes: 更新
* @Author: 玄尘
* @Date : 2021/7/23 11:03
* @param $data
*/
public function updateLog($data)
{
$this->log->outsource = $data;
$this->log->save();
}
}

View File

@@ -7,11 +7,13 @@ use App\Models\Welfare;
use App\Models\WelfareOrder;
use App\Models\WelfarePayment;
use Carbon\Carbon;
use Illuminate\Support\Str;
use XuanChen\WoUnicom\Action\Init;
use XuanChen\WoUnicom\Action\Order;
use XuanChen\WoUnicom\Action\Query;
use XuanChen\WoUnicom\Action\Refund;
use XuanChen\WoUnicom\Action\Sign;
use XuanChen\WoUnicom\Traits\Log;
/**
* 沃钱包支付
@@ -19,6 +21,8 @@ use XuanChen\WoUnicom\Action\Sign;
class WoUnicom
{
use Log;
/**
* Notes: 下单
* @Author: 玄尘
@@ -42,7 +46,10 @@ class WoUnicom
*/
public function query()
{
return (new Query());
$action = new Query();
$action->setConfig();
return $action;
}
/**
@@ -92,13 +99,13 @@ class WoUnicom
$res = $this->sign()->setParams($data)->start();
//日志
$this->unicomLog($data, $res);
$this->createLog($data, $res);
//验签成功
if ($res === true) {
//福利订单
if (str_contains($data['orderid'], 'WEAL')) {
if (Str::is('WEAL*', $data['orderid'])) {
$order = WelfareOrder::where('orderid', $data['orderid'])->first();
if ($order && $order->status == 'UNPAY') {
$payment = $order->payment;
@@ -112,6 +119,7 @@ class WoUnicom
} else {
$order = \App\Models\Order::where('orderid', $data['orderid'])->first();
if ($order && $order->state == 'UNPAY') {
$payment = \App\Models\Payment::where('orderable_type', get_class($order))
->where('orderable_id', $order->id)
@@ -127,35 +135,14 @@ class WoUnicom
}
}
$this->updateLog(['SUCCESS']);
return 'SUCCESS';
} else {
$this->updateLog(['验签失败']);
return '验签失败';
}
}
/**
* Notes: 输入日志
* @Author: 玄尘
* @Date : 2021/5/11 15:58
* @param $data
*/
public function unicomLog($data, $str)
{
$inputData = [
'orderId' => $data['orderid'],
'payFloodId' => $data['payfloodid'],
'payResult' => $data['payresult'],
'payBalance' => $data['paybalance'],
'paymentBalanceDetail' => $data['paymentbalancedetail'],
'respTime' => $data['resptime'],
'source' => [
'data' => $data,
'check_sign' => $str,
],
];
return \App\Models\Wounicom::create($inputData);
}
}