其余文件
This commit is contained in:
91
app/common/server/DouGong/BaseAsync.php
Normal file
91
app/common/server/DouGong/BaseAsync.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\server\DouGong;
|
||||
|
||||
use app\common\enum\IntegralOrderEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\logic\IntegralOrderRefundLogic;
|
||||
use app\common\logic\PayNotifyLogic;
|
||||
use app\common\model\integral\IntegralOrder;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\order\OrderTrade;
|
||||
use app\common\model\RechargeOrder;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\facade\Log;
|
||||
|
||||
class BaseAsync
|
||||
{
|
||||
protected $async_result = [];
|
||||
protected $async_success = false;
|
||||
protected $async_message = '异步信息处理失败';
|
||||
|
||||
protected $config;
|
||||
protected $params;
|
||||
|
||||
function __construct(array $result, array $params = [])
|
||||
{
|
||||
$this->async_result = $result;
|
||||
$this->params = $params;
|
||||
|
||||
$this->initAdminConfig();
|
||||
}
|
||||
|
||||
private function initAdminConfig()
|
||||
{
|
||||
$adminConfig = ConfigServer::get('hfdg_dev_set');
|
||||
|
||||
$this->config['rsa_huifu_public_key'] = $adminConfig['rsa_huifu_public_key'] ?? '';
|
||||
}
|
||||
|
||||
function checkAsync()
|
||||
{
|
||||
$data = $this->async_result;
|
||||
|
||||
try {
|
||||
if (! isset($data['resp_data']) || ! isset($data['sign'])) {
|
||||
return $this;
|
||||
}
|
||||
if (! BaseFunc::verifySign_sort($data['sign'], $data['resp_data'], $this->config['rsa_huifu_public_key'])) {
|
||||
Log::write('验签失败', 'hfdg_async_data');
|
||||
return $this;
|
||||
}
|
||||
|
||||
Log::write($data, 'hfdg_async_data');
|
||||
|
||||
$data['resp_data'] = (array) json_decode($this->async_result['resp_data'], true);
|
||||
|
||||
// 00000000 受理成功 00000100 下单成功
|
||||
$this->async_success = in_array($data['resp_data']['resp_code'], [ '00000000', '00000100' ]);
|
||||
$this->async_message = $data['resp_data']['resp_desc'];
|
||||
|
||||
} catch(\Throwable $e) {
|
||||
$this->async_message = $e->getMessage();
|
||||
Log::write($e->__toString(), 'hfdg_async_error');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getCheckSuccess()
|
||||
{
|
||||
return $this->async_success;
|
||||
}
|
||||
}
|
||||
80
app/common/server/DouGong/BaseFunc.php
Normal file
80
app/common/server/DouGong/BaseFunc.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\server\DouGong;
|
||||
|
||||
class BaseFunc
|
||||
{
|
||||
static function json($data)
|
||||
{
|
||||
return json_encode($data, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
static function get_data_json(array $data) : array
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$data[$key] = static::json($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 私钥加签(对数据源排序),可用于 V2 版本接口数据加签
|
||||
* @param int $alg 默认 OPENSSL_ALGO_SHA256
|
||||
*
|
||||
* @return string 签名串
|
||||
*/
|
||||
static function sha_with_rsa_sign($data, $rsaPrivateKey, int $alg = OPENSSL_ALGO_SHA256): string
|
||||
{
|
||||
ksort($data);
|
||||
|
||||
$data = static::json(static::get_data_json($data));
|
||||
|
||||
$key = "-----BEGIN PRIVATE KEY-----\n" .
|
||||
wordwrap($rsaPrivateKey, 64, "\n", true) .
|
||||
"\n-----END PRIVATE KEY-----";
|
||||
|
||||
$signature = '';
|
||||
|
||||
openssl_sign($data, $signature, $key, $alg);
|
||||
|
||||
return base64_encode($signature);
|
||||
}
|
||||
|
||||
/**
|
||||
* 汇付公钥验签(对数据源排序),可用于 V2 版本接口返回数据验签
|
||||
*
|
||||
* @param string $signature 签文
|
||||
* @param string $data 原数据(array)
|
||||
* @param string $rsaPublicKey 公钥
|
||||
* @param int $alg 默认 OPENSSL_ALGO_SHA256
|
||||
*
|
||||
* @return false|int 验证结果:成功/失败
|
||||
*/
|
||||
static function verifySign_sort(string $signature, string $data, string $rsaPublicKey, int $alg = OPENSSL_ALGO_SHA256)
|
||||
{
|
||||
$key = "-----BEGIN PUBLIC KEY-----\n" .
|
||||
wordwrap($rsaPublicKey, 64, "\n", true) .
|
||||
"\n-----END PUBLIC KEY-----";
|
||||
|
||||
return openssl_verify($data, base64_decode($signature), $key, $alg);
|
||||
}
|
||||
}
|
||||
158
app/common/server/DouGong/BaseRequest.php
Normal file
158
app/common/server/DouGong/BaseRequest.php
Normal file
@ -0,0 +1,158 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\server\DouGong;
|
||||
|
||||
use Alipay\EasySDK\Kernel\Base;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\model\Pay;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user\UserAuth;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\WeChatServer;
|
||||
use Requests;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* @notes 请求
|
||||
* 文档 https://paas.huifu.com/partners/api/#/
|
||||
* author lbzy
|
||||
* @datetime 2023-09-28 09:27:16
|
||||
* @class Request
|
||||
* @package app\common\server\DouGong
|
||||
*/
|
||||
abstract class BaseRequest
|
||||
{
|
||||
protected $params;
|
||||
protected $userInfo;
|
||||
protected $userAuth;
|
||||
protected $config;
|
||||
|
||||
protected $request_host = 'https://api.huifu.com';
|
||||
protected $request_uri;
|
||||
protected $request_data = [
|
||||
'sys_id' => '',
|
||||
'product_id' => '',
|
||||
'data' => [],
|
||||
// 'sign' => '',
|
||||
];
|
||||
protected $request_result = [];
|
||||
protected $request_success = false;
|
||||
protected $request_message = '';
|
||||
|
||||
/**
|
||||
* @param array $params 参数
|
||||
* $params['pay_way'] 支付方式
|
||||
* $params['client'] 用户client
|
||||
* $params['form'] 订单类型 trade:商城总订单 order:商城订单 recharge:充值订单 integral:积分订单
|
||||
* $params['order_id'] 订单id
|
||||
* $params['user_id'] 用户id
|
||||
*/
|
||||
function __construct(array $params)
|
||||
{
|
||||
$this->params = $params;
|
||||
|
||||
$this->initAdminConfig();
|
||||
|
||||
$this->initBaseParams();
|
||||
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
protected function initialize(){}
|
||||
|
||||
protected function initBaseParams()
|
||||
{
|
||||
$this->request_data['sys_id'] = $this->config['sys_id'];
|
||||
$this->request_data['product_id'] = $this->config['product_id'];
|
||||
// $this->request_data['huifu_id'] = $this->config['huifu_id'];
|
||||
}
|
||||
|
||||
function initAdminConfig()
|
||||
{
|
||||
$adminConfig = ConfigServer::get('hfdg_dev_set');
|
||||
|
||||
$this->config['sys_id'] = $adminConfig['sys_id'] ?? '';
|
||||
$this->config['product_id'] = $adminConfig['product_id'] ?? '';
|
||||
$this->config['huifu_id'] = $adminConfig['huifu_id'] ?? '';
|
||||
$this->config['rsa_merch_private_key'] = $adminConfig['rsa_merch_private_key'] ?? '';
|
||||
$this->config['rsa_merch_public_key'] = $adminConfig['rsa_merch_public_key'] ?? '';
|
||||
$this->config['rsa_huifu_public_key'] = $adminConfig['rsa_huifu_public_key'] ?? '';
|
||||
}
|
||||
|
||||
protected function beforeRequestCheck() : bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
function request(): BaseRequest
|
||||
{
|
||||
try {
|
||||
|
||||
if (! $this->beforeRequestCheck()) {
|
||||
throw new \Exception($this->request_message);
|
||||
}
|
||||
|
||||
$data = $this->request_data;
|
||||
|
||||
$data['data'] = BaseFunc::get_data_json($data['data']);
|
||||
|
||||
$data['sign'] = BaseFunc::sha_with_rsa_sign($data['data'], $this->config['rsa_merch_private_key']);
|
||||
|
||||
$result = Requests::post($this->request_host . $this->request_uri, [
|
||||
'Content-Type' => 'application/json',
|
||||
'charset' => 'UTF-8',
|
||||
], BaseFunc::json($data));
|
||||
|
||||
$this->request_result = (array) json_decode($result->body, true);
|
||||
|
||||
if (app()->isDebug()) {
|
||||
Log::write($this->request_result, 'hfdg_request_result');
|
||||
Log::write($result->body, 'hfdg_request_result_body');
|
||||
Log::write($this->params, 'hfdg_request_params');
|
||||
}
|
||||
} catch(\Throwable $e) {
|
||||
$this->request_message = $e->getMessage();
|
||||
Log::write($e->__toString(), 'hfdg_request_error');
|
||||
}
|
||||
|
||||
$this->checkRequestResult();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function checkRequestResult()
|
||||
{
|
||||
if (! isset($this->request_result['data']['resp_code'])) {
|
||||
$this->request_success = false;
|
||||
$this->request_message = $this->request_message ? : '请求失败';
|
||||
} else {
|
||||
// 00000000 受理成功 00000100 下单成功
|
||||
$this->request_success = in_array($this->request_result['data']['resp_code'], [ '00000000', '00000100' ]);
|
||||
$this->request_message = $this->request_result['data']['resp_desc'];
|
||||
if (! $this->request_success) {
|
||||
Log::write($this->request_result, 'hfdg_request_result');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getRequestResult()
|
||||
{
|
||||
return $this->request_result;
|
||||
}
|
||||
}
|
||||
65
app/common/server/DouGong/pay/MerchantBusinessConfig.php
Normal file
65
app/common/server/DouGong/pay/MerchantBusinessConfig.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\server\DouGong\pay;
|
||||
|
||||
use app\common\server\DouGong\BaseRequest;
|
||||
|
||||
/**
|
||||
* @notes 微信商户配置
|
||||
* https://paas.huifu.com/partners/api/#/shgl/shjj/api_shjj_wxshpz
|
||||
* author lbzy
|
||||
* @datetime 2023-10-26 17:12:11
|
||||
* @class MerchantBusinessConfig
|
||||
* @package app\common\server\DouGong\pay
|
||||
*/
|
||||
class MerchantBusinessConfig extends BaseRequest
|
||||
{
|
||||
protected $request_uri = '/v2/merchant/busi/config';
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
// 请求流水号
|
||||
$this->request_data['data']['req_seq_id'] = time() . mt_rand(100000, 999999);
|
||||
// 请求日期req_date
|
||||
$this->request_data['data']['req_date'] = date("Ymd");
|
||||
// 商户id
|
||||
$this->request_data['data']['huifu_id'] = $this->config['huifu_id'];
|
||||
// 业务开通类型
|
||||
$this->request_data['data']['fee_type'] = '01';
|
||||
// 公众号
|
||||
if (isset($this->params['oa_app_id'])) {
|
||||
$this->request_data['data']['wx_woa_app_id'] = $this->params['oa_app_id'];
|
||||
// $this->request_data['data']['wx_woa_path'] = request()->domain() . '/';
|
||||
}
|
||||
// 小程序
|
||||
if (isset($this->params['mnp_app_id'])) {
|
||||
$this->request_data['data']['wx_applet_app_id'] = $this->params['mnp_app_id'];
|
||||
}
|
||||
}
|
||||
|
||||
function getConfigResult() : array
|
||||
{
|
||||
return [
|
||||
'code' => intval($this->request_success),
|
||||
'msg' => $this->request_message,
|
||||
'show' => 0,
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\server\DouGong\pay;
|
||||
|
||||
use app\common\server\DouGong\BaseRequest;
|
||||
|
||||
class MerchantBusinessConfigQuery extends BaseRequest
|
||||
{
|
||||
protected $request_uri = '/v2/merchant/busi/config/query';
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
// 请求流水号
|
||||
$this->request_data['data']['req_seq_id'] = time() . mt_rand(100000, 999999);
|
||||
// 请求日期req_date
|
||||
$this->request_data['data']['req_date'] = date("Ymd");
|
||||
// 商户id
|
||||
$this->request_data['data']['huifu_id'] = $this->config['huifu_id'];
|
||||
}
|
||||
}
|
||||
315
app/common/server/DouGong/pay/PayZhengSao.php
Normal file
315
app/common/server/DouGong/pay/PayZhengSao.php
Normal file
@ -0,0 +1,315 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\server\DouGong\pay;
|
||||
|
||||
use app\common\enum\ClientEnum;
|
||||
use app\common\enum\IntegralOrderEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\logic\IntegralOrderRefundLogic;
|
||||
use app\common\logic\PayNotifyLogic;
|
||||
use app\common\model\integral\IntegralOrder;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\order\OrderTrade;
|
||||
use app\common\model\RechargeOrder;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user\UserAuth;
|
||||
use app\common\server\DouGong\BaseRequest;
|
||||
use app\common\server\WeChatServer;
|
||||
use Endroid\QrCode\QrCode;
|
||||
|
||||
/**
|
||||
* @notes 聚合正扫
|
||||
* author lbzy
|
||||
* @datetime 2023-09-28 16:13:41
|
||||
* @class PayZhengSao
|
||||
* @package app\common\server\DouGong\pay
|
||||
*/
|
||||
class PayZhengSao extends BaseRequest
|
||||
{
|
||||
protected $request_uri = '/v2/trade/payment/jspay';
|
||||
|
||||
private $pays = [
|
||||
PayEnum::HFDG_WECHAT => [
|
||||
ClientEnum::mnp => 'T_MINIAPP',
|
||||
ClientEnum::oa => 'T_JSAPI',
|
||||
ClientEnum::ios => 'T_MINIAPP',
|
||||
ClientEnum::android => 'T_MINIAPP',
|
||||
ClientEnum::pc => 'T_JSAPI',
|
||||
ClientEnum::h5 => 'T_MINIAPP',
|
||||
],
|
||||
PayEnum::HFDG_ALIPAY => [
|
||||
// ClientEnum::mnp => 'A_JSAPI',
|
||||
// ClientEnum::oa => 'A_JSAPI',
|
||||
ClientEnum::ios => 'A_NATIVE',
|
||||
ClientEnum::android => 'A_NATIVE',
|
||||
ClientEnum::pc => 'A_NATIVE',
|
||||
ClientEnum::h5 => 'A_NATIVE',
|
||||
],
|
||||
];
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
$this->initUser();
|
||||
$this->initRequestData();
|
||||
$this->parseOrder();
|
||||
}
|
||||
|
||||
private function initUser(): void
|
||||
{
|
||||
if (isset($this->params['user_id']) && $this->params['user_id'] > 0) {
|
||||
$this->userInfo = User::findOrEmpty($this->params['user_id'])->toArray();
|
||||
}
|
||||
|
||||
if (isset($this->userInfo['id']) && $this->params['pay_way'] == PayEnum::HFDG_WECHAT) {
|
||||
switch ($this->params['client'] ?? '') {
|
||||
case ClientEnum::mnp:
|
||||
case ClientEnum::h5:
|
||||
case ClientEnum::ios:
|
||||
case ClientEnum::android:
|
||||
$this->userAuth = UserAuth::where('user_id', $this->params['user_id'])
|
||||
->where('client', $this->params['client'])
|
||||
->order('id desc')
|
||||
->findOrEmpty()->toArray();
|
||||
$wechat_config = WeChatServer::getMnpConfig();
|
||||
break;
|
||||
case ClientEnum::oa:
|
||||
case ClientEnum::pc:
|
||||
$this->userAuth = UserAuth::where('user_id', $this->params['user_id'])
|
||||
->where('client', $this->params['client'])
|
||||
->order('id desc')
|
||||
->findOrEmpty()->toArray();
|
||||
$wechat_config = WeChatServer::getOaConfig();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$this->config['appid'] = $wechat_config['app_id'] ?? '';
|
||||
$this->config['sub_appid'] = $wechat_config['app_id'] ?? '';
|
||||
|
||||
$this->request_data['data']['wx_data']['sub_appid'] = $this->config['sub_appid'] ?? '';
|
||||
$this->request_data['data']['wx_data']['openid'] = $this->userAuth['openid'] ?? '';
|
||||
$this->request_data['data']['wx_data']['sub_openid'] = $this->userAuth['openid'] ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
protected function beforeRequestCheck() : bool
|
||||
{
|
||||
if ($this->params['pay_way'] == PayEnum::HFDG_WECHAT && empty($this->userAuth['openid'])) {
|
||||
$this->request_message = '支付失败:授权信息失效';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function initRequestData()
|
||||
{
|
||||
// 请求日期req_date
|
||||
$this->request_data['data']['req_date'] = date("Ymd");
|
||||
// 交易类型trade_type
|
||||
$this->request_data['data']['trade_type'] = $this->pays[$this->params['pay_way']][$this->params['client']];
|
||||
// 商户id
|
||||
$this->request_data['data']['huifu_id'] = $this->config['huifu_id'];
|
||||
// 备注
|
||||
$this->request_data['data']['remark'] = implode('-', [
|
||||
$this->params['pay_way'],
|
||||
$this->params['client'],
|
||||
$this->params['from'],
|
||||
$this->params['order_id'],
|
||||
]);
|
||||
// 回调
|
||||
if ($this->params['pay_way'] == PayEnum::HFDG_WECHAT) {
|
||||
$this->request_data['data']['notify_url'] = (string) url('pay/hfdgPayWechatNotify', [], false, true);
|
||||
}
|
||||
if ($this->params['pay_way'] == PayEnum::HFDG_ALIPAY) {
|
||||
$this->request_data['data']['notify_url'] = (string) url('pay/hfdgPayAlipayNotify', [], false, true);
|
||||
}
|
||||
}
|
||||
|
||||
function getPayResult() : array
|
||||
{
|
||||
if ($this->request_success) {
|
||||
// 记录请求时间等信息
|
||||
$update = [
|
||||
'hfdg_params' => [
|
||||
'pay_request_time' => $_SERVER['REQUEST_TIME'],
|
||||
'pay_request_date' => $this->request_data['data']['req_date'],
|
||||
'req_seq_id' => $this->request_data['data']['req_seq_id'],
|
||||
],
|
||||
];
|
||||
|
||||
switch ($this->params['from']) {
|
||||
case 'trade':
|
||||
OrderTrade::update($update, [ [ 'id', '=', $this->params['order_id'] ] ]);
|
||||
Order::update($update, [ [ 'trade_id', '=', $this->params['order_id'] ] ]);
|
||||
break;
|
||||
case 'order':
|
||||
Order::update($update, [ [ 'id', '=', $this->params['order_id'] ] ]);
|
||||
break;
|
||||
case 'recharge':
|
||||
RechargeOrder::update($update, [ [ 'id', '=', $this->params['order_id'] ] ]);
|
||||
break;
|
||||
case 'integral':
|
||||
IntegralOrder::update($update, [ [ 'id', '=', $this->params['order_id'] ] ]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$data = '';
|
||||
$code = 1;
|
||||
|
||||
if ($this->params['pay_way'] == PayEnum::HFDG_WECHAT) {
|
||||
switch ($this->params['client'] ?? '') {
|
||||
case ClientEnum::mnp:
|
||||
case ClientEnum::oa:
|
||||
case ClientEnum::pc:
|
||||
case ClientEnum::h5:
|
||||
case ClientEnum::ios:
|
||||
case ClientEnum::android:
|
||||
$data = json_decode($this->request_result['data']['pay_info'], true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->params['pay_way'] == PayEnum::HFDG_ALIPAY) {
|
||||
$code = 10001;
|
||||
switch ($this->params['client'] ?? '') {
|
||||
case ClientEnum::pc:
|
||||
$qrCode = new QrCode();
|
||||
$qrCode->setText($this->request_result["data"]["qr_code"]);
|
||||
$qrCode->setSize(1000);
|
||||
$base64 = chunk_split(base64_encode($qrCode->writeString()));
|
||||
$data = 'data:image/png;base64,' . $base64;
|
||||
break;
|
||||
case ClientEnum::h5:
|
||||
case ClientEnum::ios:
|
||||
case ClientEnum::android:
|
||||
$data = $this->request_result["data"]["qr_code"];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'code' => $code,
|
||||
'msg' => $this->request_message,
|
||||
'show' => 0,
|
||||
'pay_way' => $this->params['pay_way'],
|
||||
'data' => $data,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => $this->request_message,
|
||||
'show' => 1,
|
||||
'pay_way' => $this->params['pay_way'],
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
|
||||
protected function parseOrder()
|
||||
{
|
||||
// 请求流水号
|
||||
$this->request_data['data']['req_seq_id'] = $this->params['order']['sn'] . mt_rand(100000, 999999);
|
||||
// 交易金额
|
||||
$this->request_data['data']['trans_amt'] = bcadd($this->params['order']['order_amount'], 0, 2);
|
||||
// 商品描述
|
||||
switch ($this->params['from']) {
|
||||
case 'trade':
|
||||
$this->request_data['data']['goods_desc'] = "商品总订单";
|
||||
break;
|
||||
case 'order':
|
||||
$this->request_data['data']['goods_desc'] = "商品子订单";
|
||||
break;
|
||||
case 'recharge':
|
||||
$this->request_data['data']['goods_desc'] = "充值";
|
||||
break;
|
||||
case 'integral':
|
||||
$this->request_data['data']['goods_desc'] = "积分商城";
|
||||
break;
|
||||
default:
|
||||
$this->request_data['data']['goods_desc'] = "商品";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static function asyncSuccessDeal($async_result)
|
||||
{
|
||||
$data = (array) json_decode($async_result['resp_data'], true);
|
||||
|
||||
$remarks = explode('-', $data['remark']);
|
||||
|
||||
switch ($remarks[2]) {
|
||||
case 'order':
|
||||
$order = Order::findOrEmpty($remarks[3]);
|
||||
if (! $order || $order['pay_status'] >= PayEnum::ISPAID) {
|
||||
break ;
|
||||
}
|
||||
PayNotifyLogic::handle('order', $order['order_sn'], [ 'transaction_id' => $data['hf_seq_id'] ]);
|
||||
break;
|
||||
|
||||
case 'trade':
|
||||
$order_trade = OrderTrade::findOrEmpty($remarks[3]);
|
||||
|
||||
$orders = Order::where(['trade_id' => $remarks[3] ])->select();
|
||||
foreach ($orders as $order) {
|
||||
if (!$order || $order['pay_status'] >= PayEnum::ISPAID) {
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
PayNotifyLogic::handle('trade', $order_trade['t_sn'], [ 'transaction_id' => $data['hf_seq_id'] ]);
|
||||
break;
|
||||
|
||||
case 'recharge':
|
||||
$order = RechargeOrder::findOrEmpty($remarks[3]);
|
||||
if (! $order || $order['pay_status'] >= PayEnum::ISPAID) {
|
||||
break ;
|
||||
}
|
||||
PayNotifyLogic::handle('recharge', $order['order_sn'], [ 'transaction_id' => $data['hf_seq_id'] ]);
|
||||
break;
|
||||
|
||||
case 'integral':
|
||||
$order = IntegralOrder::findOrEmpty($remarks[3]);
|
||||
if (! $order || $order['refund_status'] == IntegralOrderEnum::IS_REFUND) {
|
||||
// 没有订单记录 或者 订单已发生退款 中断后续操作
|
||||
break ;
|
||||
}
|
||||
if ($order['order_status'] == IntegralOrderEnum::ORDER_STATUS_DOWN) {
|
||||
// 收到支付回调时,订单已被关闭, 则进行退款操作
|
||||
IntegralOrderRefundLogic::refundOrderAmount($order['id']);
|
||||
break ;
|
||||
}
|
||||
|
||||
if ($order['pay_status'] >= PayEnum::ISPAID) {
|
||||
break ;
|
||||
}
|
||||
|
||||
PayNotifyLogic::handle('integral', $order['order_sn'], [ 'transaction_id' => $data['hf_seq_id'] ]);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
109
app/common/server/DouGong/pay/PayZhengsaoRefund.php
Normal file
109
app/common/server/DouGong/pay/PayZhengsaoRefund.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\server\DouGong\pay;
|
||||
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\model\integral\IntegralOrderRefund;
|
||||
use app\common\model\order\OrderRefund;
|
||||
use app\common\server\DouGong\BaseRequest;
|
||||
|
||||
/**
|
||||
* @notes 退款
|
||||
* author lbzy
|
||||
* @datetime 2023-10-23 14:45:05
|
||||
* @class PayZhengsaoRefund
|
||||
* @package app\common\server\DouGong\pay
|
||||
*/
|
||||
class PayZhengsaoRefund extends BaseRequest
|
||||
{
|
||||
protected $request_uri = '/v2/trade/payment/scanpay/refund';
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
$this->initRequestData();
|
||||
}
|
||||
|
||||
protected function initRequestData()
|
||||
{
|
||||
// 商户id
|
||||
$this->request_data['data']['huifu_id'] = $this->config['huifu_id'];
|
||||
// 请求日期req_date
|
||||
$this->request_data['data']['req_date'] = date("Ymd");
|
||||
// 退款金额
|
||||
$this->request_data['data']['ord_amt'] = bcadd($this->params['refund']['money'], 0, 2);
|
||||
// 退款单号
|
||||
if ($this->params['from'] == 'order') {
|
||||
$this->request_data['data']['req_seq_id'] = OrderRefund::where('id', $this->params['refund']['id'])->value('refund_sn');
|
||||
}
|
||||
if ($this->params['from'] == 'integral') {
|
||||
$this->request_data['data']['req_seq_id'] = IntegralOrderRefund::where('id', $this->params['refund']['id'])->value('refund_sn');
|
||||
}
|
||||
// 原全局流水号
|
||||
$this->request_data['data']['org_hf_seq_id'] = $this->params['order']['transaction_id'];
|
||||
// 原请求日期org_req_date
|
||||
$this->request_data['data']['org_req_date'] = $this->params['order']['hfdg_params']['pay_request_date'];
|
||||
|
||||
$this->request_data['data']['remark'] = implode('-', [
|
||||
$this->params['from'],
|
||||
$this->params['order']['id'],
|
||||
$this->params['refund']['id'],
|
||||
]);
|
||||
|
||||
// 回调
|
||||
// $this->request_data['data']['notify_url'];
|
||||
}
|
||||
|
||||
function getRefundResult()
|
||||
{
|
||||
if ($this->request_success && in_array($this->request_result['data']['trans_stat'], [ 'P', 'S' ])) {
|
||||
// 记录请求时间等信息
|
||||
$update = [
|
||||
'hfdg_params' => [
|
||||
'refund_request_time' => $_SERVER['REQUEST_TIME'],
|
||||
'refund_request_date' => $this->request_data['data']['req_date'],
|
||||
],
|
||||
];
|
||||
|
||||
switch ($this->params['from']) {
|
||||
case 'order':
|
||||
OrderRefund::update($update, [ [ 'id', '=', $this->params['refund']['id'] ] ]);
|
||||
break;
|
||||
case 'integral':
|
||||
IntegralOrderRefund::update($update, [ [ 'id', '=', $this->params['refund']['id'] ] ]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return [
|
||||
'code' => 1,
|
||||
'msg' => $this->request_message,
|
||||
'show' => 0,
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => $this->request_message,
|
||||
'show' => 0,
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user