Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ccaccbd129 | |||
| b677771328 | |||
| e640647709 | |||
| f49481ad29 | |||
| 3d867be82d | |||
| a803fc2f1d | |||
| 32b76b30d9 | |||
| bdf46a01ec | |||
| a34d344110 | |||
| a60851f892 |
@@ -5,7 +5,7 @@
|
|||||||
"homepage": "http://git.yuzhankeji.cn/xuanchen/WoUnicom.git",
|
"homepage": "http://git.yuzhankeji.cn/xuanchen/WoUnicom.git",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "玄尘",
|
"name": "xuanchen",
|
||||||
"email": "122383162@qq.com"
|
"email": "122383162@qq.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ return [
|
|||||||
'uri' => [
|
'uri' => [
|
||||||
'unicom' => [
|
'unicom' => [
|
||||||
//下单
|
//下单
|
||||||
'order' => 'https://www.unicompayment.com/wappay3.0/httpservice/wapPayPageAction.do?reqcharset=UTF-8',
|
'order' => 'https://epay.10010.com/wappay3.0/httpservice/wapPayPageAction.do?reqcharset=UTF-8',
|
||||||
//查询
|
//查询
|
||||||
'query' => 'https://www.unicompayment.com/CashierWeb/query/order.htm?reqCharSet=UTF-8',
|
'query' => 'https://epay.10010.com/CashierWeb/query/order.htm?reqCharSet=UTF-8',
|
||||||
//单笔退款
|
//单笔退款
|
||||||
'refund' => 'https://www.unicompayment.com/CashierWeb/trade/singleRefund.htm?reqCharSet=UTF-8',
|
'refund' => 'https://epay.10010.com/CashierWeb/trade/singleRefund.htm?reqCharSet=UTF-8',
|
||||||
],
|
],
|
||||||
'ysd' => [
|
'ysd' => [
|
||||||
'order' => env('APP_URL', 'https://card.ysd-bs.com'),
|
'order' => env('APP_URL', 'https://card.ysd-bs.com'),
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ class Init
|
|||||||
$result = (bool) openssl_verify($signStr, $sign, $pub_key_id, 'SHA256');
|
$result = (bool) openssl_verify($signStr, $sign, $pub_key_id, 'SHA256');
|
||||||
openssl_free_key($pub_key_id);
|
openssl_free_key($pub_key_id);
|
||||||
} else {
|
} else {
|
||||||
throw new \Exception('私钥格式有误');
|
throw new \Exception('公钥格式有误');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@@ -156,8 +156,7 @@ class Init
|
|||||||
{
|
{
|
||||||
$signStr = $this->getSignString();
|
$signStr = $this->getSignString();
|
||||||
$private_key = $this->getPrivate();
|
$private_key = $this->getPrivate();
|
||||||
|
$privKeyId = openssl_get_privatekey($private_key);
|
||||||
$privKeyId = openssl_get_privatekey($private_key);
|
|
||||||
|
|
||||||
if (!$privKeyId) {
|
if (!$privKeyId) {
|
||||||
throw new \Exception('私钥格式有误');
|
throw new \Exception('私钥格式有误');
|
||||||
@@ -301,7 +300,6 @@ class Init
|
|||||||
}
|
}
|
||||||
|
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $client->request('POST', $url, [
|
$response = $client->request('POST', $url, [
|
||||||
'form_params' => $paramArray,
|
'form_params' => $paramArray,
|
||||||
@@ -312,22 +310,27 @@ class Init
|
|||||||
if ($response->getStatusCode() == 200) {
|
if ($response->getStatusCode() == 200) {
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
$content = str_replace(["\r\n", "\n", "\r", '/n', "\\n",], '&', $body->getContents());
|
$content = str_replace(["\r\n", "\n", "\r", '/n', "\\n",], '&', $body->getContents());
|
||||||
|
|
||||||
parse_str($content, $data);
|
parse_str($content, $data);
|
||||||
|
|
||||||
if ($data['transRet'] != 'SUCCESS') {
|
$this->data = $data;
|
||||||
$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 {
|
} else {
|
||||||
$this->code = false;
|
throw new \Exception('未正常返回数据');
|
||||||
$this->message = '接口错误 Post';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
$this->code = false;
|
$this->code = false;
|
||||||
$this->message = '接口错误 Post' . $exception->getMessage();
|
$this->message = '接口错误 ' . $exception->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,28 @@ class Query extends Init
|
|||||||
|
|
||||||
public function start()
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class Refund extends Init
|
|||||||
'orderDate' => $order->created_at->format('Ymd'),
|
'orderDate' => $order->created_at->format('Ymd'),
|
||||||
'payJournl' => $order->payment->out_trade_no,
|
'payJournl' => $order->payment->out_trade_no,
|
||||||
'merReqTime' => Carbon::now()->format('YmdHis'),
|
'merReqTime' => Carbon::now()->format('YmdHis'),
|
||||||
'amount' => -1,
|
'amount' => $order->payment->amount * 100,
|
||||||
'reason' => '退款',
|
'reason' => '退款',
|
||||||
'signType' => 'RSA_SHA256',
|
'signType' => 'RSA_SHA256',
|
||||||
];
|
];
|
||||||
|
|||||||
17
src/Model/Wounicom.php
Normal file
17
src/Model/Wounicom.php
Normal 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
46
src/Traits/Log.php
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
127
src/WoUnicom.php
127
src/WoUnicom.php
@@ -2,13 +2,21 @@
|
|||||||
|
|
||||||
namespace XuanChen\WoUnicom;
|
namespace XuanChen\WoUnicom;
|
||||||
|
|
||||||
|
use App\Helpers\Helper;
|
||||||
|
use App\Models\ActivitySchoolOrder;
|
||||||
|
use App\Models\ActivityPetroOrder;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
|
use App\Models\Welfare;
|
||||||
|
use App\Models\WelfareOrder;
|
||||||
|
use App\Models\WelfarePayment;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use XuanChen\WoUnicom\Action\Init;
|
use XuanChen\WoUnicom\Action\Init;
|
||||||
use XuanChen\WoUnicom\Action\Order;
|
use XuanChen\WoUnicom\Action\Order;
|
||||||
use XuanChen\WoUnicom\Action\Query;
|
use XuanChen\WoUnicom\Action\Query;
|
||||||
use XuanChen\WoUnicom\Action\Refund;
|
use XuanChen\WoUnicom\Action\Refund;
|
||||||
use XuanChen\WoUnicom\Action\Sign;
|
use XuanChen\WoUnicom\Action\Sign;
|
||||||
|
use XuanChen\WoUnicom\Traits\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 沃钱包支付
|
* 沃钱包支付
|
||||||
@@ -16,8 +24,11 @@ use XuanChen\WoUnicom\Action\Sign;
|
|||||||
class WoUnicom
|
class WoUnicom
|
||||||
{
|
{
|
||||||
|
|
||||||
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notes: 下单
|
* Notes: 下单
|
||||||
|
*
|
||||||
* @Author: 玄尘
|
* @Author: 玄尘
|
||||||
* @Date : 2021/4/30 9:36
|
* @Date : 2021/4/30 9:36
|
||||||
* @return \XuanChen\WoUnicom\Action\Order
|
* @return \XuanChen\WoUnicom\Action\Order
|
||||||
@@ -33,17 +44,22 @@ class WoUnicom
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Notes: 查询订单
|
* Notes: 查询订单
|
||||||
|
*
|
||||||
* @Author: 玄尘
|
* @Author: 玄尘
|
||||||
* @Date : 2021/4/30 9:39
|
* @Date : 2021/4/30 9:39
|
||||||
* @return \XuanChen\WoUnicom\Action\Query
|
* @return \XuanChen\WoUnicom\Action\Query
|
||||||
*/
|
*/
|
||||||
public function query()
|
public function query()
|
||||||
{
|
{
|
||||||
return (new Query());
|
$action = new Query();
|
||||||
|
$action->setConfig();
|
||||||
|
|
||||||
|
return $action;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notes: 退款
|
* Notes: 退款
|
||||||
|
*
|
||||||
* @Author: 玄尘
|
* @Author: 玄尘
|
||||||
* @Date : 2021/4/30 9:37
|
* @Date : 2021/4/30 9:37
|
||||||
*/
|
*/
|
||||||
@@ -58,6 +74,7 @@ class WoUnicom
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Notes: 验签
|
* Notes: 验签
|
||||||
|
*
|
||||||
* @Author: 玄尘
|
* @Author: 玄尘
|
||||||
* @Date : 2021/5/11 11:51
|
* @Date : 2021/5/11 11:51
|
||||||
* @param $params
|
* @param $params
|
||||||
@@ -72,14 +89,16 @@ class WoUnicom
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Notes: 回调数据
|
* Notes: 回调数据
|
||||||
|
*
|
||||||
* @Author: 玄尘
|
* @Author: 玄尘
|
||||||
* @Date : 2021/5/11 15:54
|
* @Date : 2021/5/11 15:54
|
||||||
* @param $params
|
* @param $params
|
||||||
*/
|
*/
|
||||||
public function callback($inputs)
|
public function callback($inputs)
|
||||||
{
|
{
|
||||||
info('weounicom inputs');
|
if (empty($inputs)) {
|
||||||
info($inputs);
|
return '缺少必要参数';
|
||||||
|
}
|
||||||
|
|
||||||
$params = str_replace('$', '&', $inputs);
|
$params = str_replace('$', '&', $inputs);
|
||||||
parse_str($params, $data);
|
parse_str($params, $data);
|
||||||
@@ -88,54 +107,80 @@ class WoUnicom
|
|||||||
$res = $this->sign()->setParams($data)->start();
|
$res = $this->sign()->setParams($data)->start();
|
||||||
|
|
||||||
//日志
|
//日志
|
||||||
$this->unicomLog($data, $res);
|
$this->createLog($data, $res);
|
||||||
|
|
||||||
//验签成功
|
//验签成功
|
||||||
if ($res === true) {
|
if ($res === true) {
|
||||||
|
$channel = Helper::getChannel($data['orderid']);
|
||||||
|
switch ($channel) {
|
||||||
|
case 'welfare':
|
||||||
|
$order = WelfareOrder::where('orderid', $data['orderid'])->first();
|
||||||
|
if ($order && $order->status == 'UNPAY') {
|
||||||
|
$payment = $order->payment;
|
||||||
|
|
||||||
$order = \App\Models\Order::where('orderid', $data['orderid'])->first();
|
$payment->paid([
|
||||||
if ($order && $order->state == 'UNPAY') {
|
'type' => 'UNICOM',
|
||||||
$payment = \App\Models\Payment::where('orderable_type', get_class($order))
|
'payfloodid' => $data['payfloodid'],
|
||||||
->where('orderable_id', $order->id)
|
]);
|
||||||
->latest()
|
$order->paid();
|
||||||
->first();
|
}
|
||||||
|
break;
|
||||||
|
case 'school':
|
||||||
|
$order = ActivitySchoolOrder::where('orderid', $data['orderid'])->first();
|
||||||
|
if ($order && $order->state == 'UNPAY') {
|
||||||
|
$payment = Payment::where('orderable_type', get_class($order))
|
||||||
|
->where('orderable_id', $order->id)
|
||||||
|
->latest()
|
||||||
|
->first();
|
||||||
|
|
||||||
$payment->state = 'SUCCESS';
|
$payment->state = 'SUCCESS';
|
||||||
$payment->out_trade_no = $data['payfloodid'];
|
$payment->out_trade_no = $data['payfloodid'];
|
||||||
$payment->type = 'UNICOM';
|
$payment->type = 'UNICOM';
|
||||||
$payment->paid_at = Carbon::now();
|
$payment->paid_at = Carbon::now();
|
||||||
$payment->save();
|
$payment->save();
|
||||||
$order->paid();
|
$order->paid();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'petro':
|
||||||
|
$order = ActivityPetroOrder::where('orderid', $data['orderid'])->first();
|
||||||
|
if ($order && $order->state == 'UNPAY') {
|
||||||
|
$payment = Payment::where('orderable_type', get_class($order))
|
||||||
|
->where('orderable_id', $order->id)
|
||||||
|
->latest()
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$payment->state = 'SUCCESS';
|
||||||
|
$payment->out_trade_no = $data['payfloodid'];
|
||||||
|
$payment->type = 'UNICOM';
|
||||||
|
$payment->paid_at = Carbon::now();
|
||||||
|
$payment->save();
|
||||||
|
$order->paid();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'web':
|
||||||
|
default:
|
||||||
|
$order = \App\Models\Order::where('orderid', $data['orderid'])->first();
|
||||||
|
if ($order && $order->state == 'UNPAY') {
|
||||||
|
$payment = Payment::where('orderable_type', get_class($order))
|
||||||
|
->where('orderable_id', $order->id)
|
||||||
|
->latest()
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$payment->state = 'SUCCESS';
|
||||||
|
$payment->out_trade_no = $data['payfloodid'];
|
||||||
|
$payment->type = 'UNICOM';
|
||||||
|
$payment->paid_at = Carbon::now();
|
||||||
|
$payment->save();
|
||||||
|
$order->paid();
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
$this->updateLog(['SUCCESS']);
|
||||||
return 'SUCCESS';
|
return 'SUCCESS';
|
||||||
} else {
|
} else {
|
||||||
|
$this->updateLog(['验签失败']);
|
||||||
return '验签失败';
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user