This commit is contained in:
Hankin 2026-04-27 11:32:30 +08:00
parent 830173e99f
commit 2d3e878e11
4 changed files with 894 additions and 687 deletions

View File

@ -0,0 +1,91 @@
<?php
namespace App\Helpers;
use DateTimeImmutable;
class TokenHelper
{
private static $secret = 'ufutx_love_util';
/**
* 生成 token
* @param int $userId 用户ID
* @param int $expiresIn 过期时间(分钟)
* @return string
*/
public static function generate($userId, $expiresIn = 60)
{
$now = time();
$expires = $now + ($expiresIn * 60);
$payload = [
'user_id' => $userId,
'iat' => $now,
'exp' => $expires
];
// 使用更简单的方式base64 编码(避免版本兼容问题)
$encoded = base64_encode(json_encode($payload));
// 添加签名
$signature = hash_hmac('sha256', $encoded, self::$secret);
return $encoded . '.' . $signature;
}
/**
* 验证 token
* @return array|false
*/
public static function verify($tokenString)
{
try {
$parts = explode('.', $tokenString);
if (count($parts) != 2) {
return false;
}
list($payloadEncoded, $signature) = $parts;
// 验证签名
$expectedSignature = hash_hmac('sha256', $payloadEncoded, self::$secret);
if (!hash_equals($expectedSignature, $signature)) {
return false;
}
// 解码 payload
$payload = json_decode(base64_decode($payloadEncoded), true);
if (!$payload) {
return false;
}
// 检查是否过期
$now = time();
if (isset($payload['exp']) && $payload['exp'] < $now) {
return false;
}
return [
'user_id' => $payload['user_id'],
'expires_at' => $payload['exp']
];
} catch (\Exception $e) {
return false;
}
}
/**
* 刷新 token
*/
public static function refresh($oldToken, $expiresIn = 60)
{
$payload = self::verify($oldToken);
if (!$payload) {
return false;
}
return self::generate($payload['user_id'], $expiresIn);
}
}

View File

@ -48,7 +48,8 @@ class EarningController extends Controller
public function updateRule(Request $request, $id) public function updateRule(Request $request, $id)
{ {
$rule = EarningRule::find($id); $rule = EarningRule::find($id);
if (empty($rule)) return $this->failure("修改失败,收益规则不存在"); if (empty($rule))
return $this->failure("修改失败,收益规则不存在");
$ratio = $request->input('ratio'); $ratio = $request->input('ratio');
if ($request->has('ratio') && $ratio != $rule->ratio) { if ($request->has('ratio') && $ratio != $rule->ratio) {
$rule->ratio = $ratio; $rule->ratio = $ratio;
@ -96,7 +97,8 @@ class EarningController extends Controller
public function accountEarnings(Request $request, $id) public function accountEarnings(Request $request, $id)
{ {
$account = EarningAccount::find($id); $account = EarningAccount::find($id);
if (empty($account)) return $this->failure('收益账号不存在'); if (empty($account))
return $this->failure('收益账号不存在');
$earnings = $account->earnings()->with('order:id,goods')->orderBy('id', 'desc')->paginate(); $earnings = $account->earnings()->with('order:id,goods')->orderBy('id', 'desc')->paginate();
return $this->success('ok', compact('account', 'earnings')); return $this->success('ok', compact('account', 'earnings'));
} }
@ -104,7 +106,8 @@ class EarningController extends Controller
public function accountWithdraws(Request $request, $id) public function accountWithdraws(Request $request, $id)
{ {
$account = EarningAccount::find($id); $account = EarningAccount::find($id);
if (empty($account)) return $this->failure('收益账号不存在'); if (empty($account))
return $this->failure('收益账号不存在');
$withdraws = $account->withdraws()->orderBy('id', 'desc')->paginate(); $withdraws = $account->withdraws()->orderBy('id', 'desc')->paginate();
return $this->success('ok', compact('account', 'withdraws')); return $this->success('ok', compact('account', 'withdraws'));
} }
@ -142,15 +145,19 @@ class EarningController extends Controller
Log::info("审核商家提现"); Log::info("审核商家提现");
try { try {
$log = EarningWithdraw::find($id); $log = EarningWithdraw::find($id);
if (empty($log)) throw new Exception("提现记录不存在"); if (empty($log))
if ($log->status == 'canceled' || ($log->status == 'finished' && empty($log->err_msg))) return $this->failure("该提现记录已审核"); throw new Exception("提现记录不存在");
if ($log->status == 'canceled' || ($log->status == 'finished' && empty($log->err_msg)))
return $this->failure("该提现记录已审核");
//获取该用户的收益账号 //获取该用户的收益账号
$account = $log->earningAccount; $account = $log->earningAccount;
if (empty($account)) throw new Exception("提现账号不存在"); if (empty($account))
throw new Exception("提现账号不存在");
$balance = $account->balance;//账户余额 $balance = $account->balance;//账户余额
$frozen_withdraw = $account->frozen_withdraw;//账户冻结提现金额 $frozen_withdraw = $account->frozen_withdraw;//账户冻结提现金额
//如果当前用户冻结提现金额 小于 本次提现金额 //如果当前用户冻结提现金额 小于 本次提现金额
if($frozen_withdraw < $log->value) throw new Exception('当前账户异常,提现金额大于实际金额'); if ($frozen_withdraw < $log->value)
throw new Exception('当前账户异常,提现金额大于实际金额');
$user = $log->user; $user = $log->user;
if ($log->way == 'alipay') { if ($log->way == 'alipay') {
$transfer_way = '支付宝'; $transfer_way = '支付宝';
@ -164,7 +171,8 @@ class EarningController extends Controller
$admin_id = auth()->id(); $admin_id = auth()->id();
if ($status == 'canceled') { if ($status == 'canceled') {
$err_msg = $request->input('err_msg'); $err_msg = $request->input('err_msg');
if (empty($err_msg)) return $this->failure("请输入拒绝理由"); if (empty($err_msg))
return $this->failure("请输入拒绝理由");
EarningWithdraw::where('id', $id)->update(['status' => $status, 'err_msg' => $err_msg, 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s')]); EarningWithdraw::where('id', $id)->update(['status' => $status, 'err_msg' => $err_msg, 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s')]);
$account->increment('balance', $log->value); $account->increment('balance', $log->value);
$account->decrement("frozen_withdraw", $log->value); $account->decrement("frozen_withdraw", $log->value);
@ -255,7 +263,8 @@ class EarningController extends Controller
} }
//提现审核列表 //提现审核列表
public function withdrawalLogs(Request $request){ public function withdrawalLogs(Request $request)
{
$keyword = $request->keyword; $keyword = $request->keyword;
$type = $request->type ?? 'saas'; $type = $request->type ?? 'saas';
$has_withdraw = 0; $has_withdraw = 0;
@ -310,20 +319,24 @@ class EarningController extends Controller
* @param $id * @param $id
* @return JsonResponse|string * @return JsonResponse|string
*/ */
public function auditWithdraw(Request $request,$id){ public function auditWithdraw(Request $request, $id)
{
try { try {
$admin_id = auth()->id(); $admin_id = auth()->id();
$log = MEarningwithdraws::where('id', $id)->where('status', 'freezing')->first(); $log = MEarningwithdraws::where('id', $id)->where('status', 'freezing')->first();
if(empty($log)) return $this->failure('该记录不存在或已被其他管理员审核'); if (empty($log))
return $this->failure('该记录不存在或已被其他管理员审核');
//获取该商户的收益账号 //获取该商户的收益账号
$account = MEarningAccount::where('m_id', $log->m_id)->where('m_user_id', 0)->first(); $account = MEarningAccount::where('m_id', $log->m_id)->where('m_user_id', 0)->first();
$balance = $account->balance;//账户余额 $balance = $account->balance;//账户余额
$frozen_withdraw = $account->frozen_withdraw;//账户冻结提现金额 $frozen_withdraw = $account->frozen_withdraw;//账户冻结提现金额
//如果当前用户冻结提现金额 小于 本次提现金额 //如果当前用户冻结提现金额 小于 本次提现金额
if($frozen_withdraw < $log->value) return $this->failure('当前账户异常,联系开发人员处理'); if ($frozen_withdraw < $log->value)
return $this->failure('当前账户异常,联系开发人员处理');
$anchor = Anchor::where('m_id', $log->m_id)->first(); $anchor = Anchor::where('m_id', $log->m_id)->first();
$openid = MerchantAccount::where('id', $log->m_id)->value('openid');//商家openid $openid = MerchantAccount::where('id', $log->m_id)->value('openid');//商家openid
if(empty($openid)) $openid = $anchor->openid; if (empty($openid))
$openid = $anchor->openid;
if ($log->way == 'alipay') { if ($log->way == 'alipay') {
$transfer_way = '支付宝'; $transfer_way = '支付宝';
} elseif ($log->way == 'weixin') { } elseif ($log->way == 'weixin') {
@ -332,14 +345,16 @@ class EarningController extends Controller
$transfer_way = '银行卡'; $transfer_way = '银行卡';
} }
$status = $request->status; $status = $request->status;
if(!in_array($status,['finished','canceled','manual'])) throw new \Exception("提供审核参数有误",1); if (!in_array($status, ['finished', 'canceled', 'manual']))
throw new \Exception("提供审核参数有误", 1);
$data = []; $data = [];
$data['remark'] = '提现已到账'; //提现备注 $data['remark'] = '提现已到账'; //提现备注
$data['out_biz_no'] = $log->trade_no; $data['out_biz_no'] = $log->trade_no;
$data['amount'] = $log->real_value;//实际到账金额 $data['amount'] = $log->real_value;//实际到账金额
$data['payee_account'] = $log->account;//支付宝账号 $data['payee_account'] = $log->account;//支付宝账号
$data['payee_real_name'] = $log->name;//支付宝绑定姓名 $data['payee_real_name'] = $log->name;//支付宝绑定姓名
if($log->alipay_id) $data['payee_account'] = $log->alipay_id; if ($log->alipay_id)
$data['payee_account'] = $log->alipay_id;
$url = ''; $url = '';
DB::beginTransaction(); DB::beginTransaction();
switch ($status) { switch ($status) {
@ -352,7 +367,10 @@ class EarningController extends Controller
$result = $ali->platTransferAccount($data); $result = $ali->platTransferAccount($data);
} }
} elseif ($log->way == 'weixin') { } elseif ($log->way == 'weixin') {
$result = \WechatService::officialUserTransferV2($log->trade_no,$log->account,$log->real_value * 100,'提现已到账'); // $result = \WechatService::officialUserTransferV2($log->trade_no,$log->account,$log->real_value * 100,'提现已到账');
// 商家转账(需用户确认)
$result = \WechatService::officialUserTransferV3($log);
} elseif ($log->way == 'bank') { } elseif ($log->way == 'bank') {
$result = \WechatService::bankTransfer($log->trade_no, $log->account, $log->name, $log->bank_code, $log->real_value * 100, '打款至个人银行卡'); $result = \WechatService::bankTransfer($log->trade_no, $log->account, $log->name, $log->bank_code, $log->real_value * 100, '打款至个人银行卡');
} }
@ -411,7 +429,8 @@ class EarningController extends Controller
break; break;
case 'canceled': //审核拒绝 case 'canceled': //审核拒绝
$reason = $request->reason; $reason = $request->reason;
if(!$reason) return $this->failure('请输入拒绝理由'); if (!$reason)
return $this->failure('请输入拒绝理由');
$account->update(['frozen_withdraw' => $frozen_withdraw - $log->value, 'balance' => $balance + $log->value]); $account->update(['frozen_withdraw' => $frozen_withdraw - $log->value, 'balance' => $balance + $log->value]);
$log->update(['status' => $status, 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'err_msg' => $request->reason]); $log->update(['status' => $status, 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'err_msg' => $request->reason]);
$data['touser'] = $openid; $data['touser'] = $openid;
@ -462,29 +481,34 @@ class EarningController extends Controller
} }
//福恋h5提现审核 //福恋h5提现审核
public function auditWithdrawH5(Request $request,$id){ public function auditWithdrawH5(Request $request, $id)
{
try { try {
$admin_id = auth()->id(); $admin_id = auth()->id();
$log = EarningWithdraw::where('id', $id)->where('status', 'freezing')->first(); $log = EarningWithdraw::where('id', $id)->where('status', 'freezing')->first();
if(empty($log)) return $this->failure('该记录不存在或已被其他管理员审核'); if (empty($log))
return $this->failure('该记录不存在或已被其他管理员审核');
//获取该用户的收益账号 //获取该用户的收益账号
$account = EarningAccount::where('user_id', $log->user_id)->first(); $account = EarningAccount::where('user_id', $log->user_id)->first();
$balance = $account->balance;//账户余额 $balance = $account->balance;//账户余额
$frozen_withdraw = $account->frozen_withdraw;//账户冻结提现金额 $frozen_withdraw = $account->frozen_withdraw;//账户冻结提现金额
//如果当前用户冻结提现金额 小于 本次提现金额 //如果当前用户冻结提现金额 小于 本次提现金额
if($frozen_withdraw < $log->value) return $this->failure('当前账户异常,联系开发人员处理'); if ($frozen_withdraw < $log->value)
return $this->failure('当前账户异常,联系开发人员处理');
$user = User::where('id', $log->user_id)->first(); $user = User::where('id', $log->user_id)->first();
$openid = $user->wechat ? $user->wechat->official_openid : ''; $openid = $user->wechat ? $user->wechat->official_openid : '';
$transfer_way = $log->way == 'alipay' ? '支付宝' : '微信';//转账方式 $transfer_way = $log->way == 'alipay' ? '支付宝' : '微信';//转账方式
$status = $request->status; $status = $request->status;
if(!in_array($status,['finished','canceled','manual'])) throw new \Exception("提供审核参数有误",1); if (!in_array($status, ['finished', 'canceled', 'manual']))
throw new \Exception("提供审核参数有误", 1);
$data = []; $data = [];
$data['remark'] = '提现已到账'; //提现备注 $data['remark'] = '提现已到账'; //提现备注
$data['out_biz_no'] = $log->trade_no; $data['out_biz_no'] = $log->trade_no;
$data['amount'] = $log->real_value;//实际到账金额 $data['amount'] = $log->real_value;//实际到账金额
$data['payee_account'] = $log->account;//支付宝账号 $data['payee_account'] = $log->account;//支付宝账号
$data['payee_real_name'] = $log->name;//支付宝绑定姓名 $data['payee_real_name'] = $log->name;//支付宝绑定姓名
if($log->alipay_id) $data['payee_account'] = $log->alipay_id; if ($log->alipay_id)
$data['payee_account'] = $log->alipay_id;
$ali = new LiveAlipayService(); $ali = new LiveAlipayService();
$url = ''; $url = '';
$alipay_real_name = empty($data['payee_real_name']) ? $data['alipay_id'] : $data['payee_real_name']; $alipay_real_name = empty($data['payee_real_name']) ? $data['alipay_id'] : $data['payee_real_name'];
@ -554,7 +578,8 @@ class EarningController extends Controller
} }
} elseif ($status == 'canceled') {//审核失败 } elseif ($status == 'canceled') {//审核失败
$reason = $request->reason; $reason = $request->reason;
if(!$reason) return $this->failure('请输入拒绝理由'); if (!$reason)
return $this->failure('请输入拒绝理由');
$account->update(['frozen_withdraw' => $frozen_withdraw - $log->value, 'balance' => $balance + $log->value]); $account->update(['frozen_withdraw' => $frozen_withdraw - $log->value, 'balance' => $balance + $log->value]);
$log->update(['status' => $status, 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'err_msg' => $request->reason]); $log->update(['status' => $status, 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'err_msg' => $request->reason]);
//todo 短信通知 公众号通知拒绝理由 //todo 短信通知 公众号通知拒绝理由
@ -608,17 +633,20 @@ class EarningController extends Controller
* @param $id * @param $id
* @return JsonResponse|string * @return JsonResponse|string
*/ */
public function auditWithdrawSaasH5(Request $request,$id){ public function auditWithdrawSaasH5(Request $request, $id)
{
try { try {
$admin_id = auth()->id(); $admin_id = auth()->id();
$log = MEarningwithdraws::where('id', $id)->where('status', 'freezing')->first(); $log = MEarningwithdraws::where('id', $id)->where('status', 'freezing')->first();
if(empty($log)) return $this->failure('该记录不存在或已被其他管理员审核'); if (empty($log))
return $this->failure('该记录不存在或已被其他管理员审核');
//获取该用户的收益账号 //获取该用户的收益账号
$account = MEarningAccount::where('m_id', $log->m_id)->where('m_user_id', $log->m_user_id)->first(); $account = MEarningAccount::where('m_id', $log->m_id)->where('m_user_id', $log->m_user_id)->first();
$balance = $account->balance;//账户余额 $balance = $account->balance;//账户余额
$frozen_withdraw = $account->frozen_withdraw;//账户冻结提现金额 $frozen_withdraw = $account->frozen_withdraw;//账户冻结提现金额
//如果当前用户冻结提现金额 小于 本次提现金额 //如果当前用户冻结提现金额 小于 本次提现金额
if($frozen_withdraw < $log->value) return $this->failure('当前账户异常,联系开发人员处理'); if ($frozen_withdraw < $log->value)
return $this->failure('当前账户异常,联系开发人员处理');
$merchant_user = MerchantUser::where('id', $log->m_user_id)->first(); $merchant_user = MerchantUser::where('id', $log->m_user_id)->first();
$status = $request->status; $status = $request->status;
if ($log->way == 'alipay') { if ($log->way == 'alipay') {
@ -628,14 +656,16 @@ class EarningController extends Controller
} elseif ($log->way == 'bank') { } elseif ($log->way == 'bank') {
$transfer_way = '银行卡'; $transfer_way = '银行卡';
} }
if(!in_array($status,['finished','canceled','manual'])) throw new \Exception("提供审核参数有误",1); if (!in_array($status, ['finished', 'canceled', 'manual']))
throw new \Exception("提供审核参数有误", 1);
$data = []; $data = [];
$data['remark'] = '提现已到账'; //提现备注 $data['remark'] = '提现已到账'; //提现备注
$data['out_biz_no'] = $log->trade_no; $data['out_biz_no'] = $log->trade_no;
$data['amount'] = $log->real_value;//实际到账金额 $data['amount'] = $log->real_value;//实际到账金额
$data['payee_account'] = $log->account;//支付宝账号 $data['payee_account'] = $log->account;//支付宝账号
$data['payee_real_name'] = $log->name;//支付宝绑定姓名 $data['payee_real_name'] = $log->name;//支付宝绑定姓名
if($log->alipay_id) $data['payee_account'] = $log->alipay_id; if ($log->alipay_id)
$data['payee_account'] = $log->alipay_id;
$ali = new LiveAlipayService(); $ali = new LiveAlipayService();
$url = ''; $url = '';
$alipay_real_name = empty($data['payee_real_name']) ? $log->alipay_id : $data['payee_real_name']; $alipay_real_name = empty($data['payee_real_name']) ? $log->alipay_id : $data['payee_real_name'];
@ -706,7 +736,8 @@ class EarningController extends Controller
break; break;
case 'canceled': //审核拒绝 case 'canceled': //审核拒绝
$reason = $request->reason; $reason = $request->reason;
if(!$reason) return $this->failure('请输入拒绝理由'); if (!$reason)
return $this->failure('请输入拒绝理由');
$account->update(['frozen_withdraw' => $frozen_withdraw - $log->value, 'balance' => $balance + $log->value]); $account->update(['frozen_withdraw' => $frozen_withdraw - $log->value, 'balance' => $balance + $log->value]);
$log->update(['status' => $status, 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'err_msg' => $request->reason]); $log->update(['status' => $status, 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'err_msg' => $request->reason]);
//todo 短信通知 公众号通知拒绝理由 //todo 短信通知 公众号通知拒绝理由
@ -781,7 +812,8 @@ class EarningController extends Controller
{ {
try { try {
$user_id = $request->input('user_id'); $user_id = $request->input('user_id');
if (empty($user_id)) throw new Exception("缺少用户id参数"); if (empty($user_id))
throw new Exception("缺少用户id参数");
$user = User::find($user_id); $user = User::find($user_id);
$euser = EarningUser::where('user_id', $user_id)->first(); $euser = EarningUser::where('user_id', $user_id)->first();
if (empty($euser)) { if (empty($euser)) {
@ -800,7 +832,8 @@ class EarningController extends Controller
{ {
try { try {
$user_id = $request->input('user_id'); $user_id = $request->input('user_id');
if (empty($user_id)) throw new Exception("缺少用户id参数"); if (empty($user_id))
throw new Exception("缺少用户id参数");
EarningUser::where('user_id', $user_id)->delete(); EarningUser::where('user_id', $user_id)->delete();
return $this->success('ok'); return $this->success('ok');
} catch (Exception $e) { } catch (Exception $e) {

View File

@ -7,6 +7,7 @@ use App\Exports\MessengerExport;
use App\Exports\ReportExport; use App\Exports\ReportExport;
use App\Facades\QrcodeRectService; use App\Facades\QrcodeRectService;
use App\Facades\WechatService; use App\Facades\WechatService;
use App\Helpers\TokenHelper;
use App\Jobs\AddUnionUser; use App\Jobs\AddUnionUser;
use App\Jobs\MakeSurveyQrcode; use App\Jobs\MakeSurveyQrcode;
use App\Jobs\SaasEarningMPNotice; use App\Jobs\SaasEarningMPNotice;
@ -41,6 +42,7 @@ use App\Models\UnionUser;
use App\Server\ReportFile; use App\Server\ReportFile;
use App\Services\LiveAlipayService; use App\Services\LiveAlipayService;
use App\Services\OrderService; use App\Services\OrderService;
use GuzzleHttp\RequestOptions;
use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController; use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Foundation\Validation\ValidatesRequests;
@ -144,6 +146,8 @@ use App\Models\Server\MerchantAdmins;
use App\Models\Server\TouristOrder; use App\Models\Server\TouristOrder;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use App\Imports\TestImport; use App\Imports\TestImport;
use GuzzleHttp\Client;
class Controller extends BaseController class Controller extends BaseController
{ {
use AuthorizesRequests, DispatchesJobs, ValidatesRequests, ResponseJson; use AuthorizesRequests, DispatchesJobs, ValidatesRequests, ResponseJson;
@ -2167,10 +2171,7 @@ class Controller extends BaseController
public function test(Request $request) public function test(Request $request)
{ {
$order = TouristOrder::find($request->order_id);
$orderService = new OrderService();
$res = $orderService->storeUftxCustomer($order);
dd($res);
} }
public function postIndex() public function postIndex()

View File

@ -1,7 +1,11 @@
<?php namespace App\Services; <?php
namespace App\Services;
use App\Helpers\TokenHelper;
use App\Models\Server\WechatSubMerchant; use App\Models\Server\WechatSubMerchant;
use DB;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
use Log; use Log;
use Carbon\Carbon; use Carbon\Carbon;
@ -11,7 +15,7 @@ use EasyWeChat\Factory;
use App\Utils\Messenger; use App\Utils\Messenger;
use App\Models\Live\Viewer; use App\Models\Live\Viewer;
use EasyWeChat\Payment\Order; use EasyWeChat\Payment\Order;
Use App\Utils\Http; use App\Utils\Http;
use App\Models\Wechat; use App\Models\Wechat;
use App\Models\PayLog; use App\Models\PayLog;
use App\Models\Order as LoveOrder; use App\Models\Order as LoveOrder;
@ -107,7 +111,8 @@ class WechatService
return $instance; return $instance;
} }
public function app(){ public function app()
{
return $this->app; return $this->app;
} }
@ -327,7 +332,8 @@ class WechatService
); );
} }
public function getClientIp() { public function getClientIp()
{
if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) { if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
$ip = getenv('HTTP_CLIENT_IP'); $ip = getenv('HTTP_CLIENT_IP');
} elseif (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) { } elseif (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
@ -835,7 +841,8 @@ class WechatService
} }
//查询订单支付成功? //查询订单支付成功?
public function orderPaid($orderid){ public function orderPaid($orderid)
{
//测试不检查 //测试不检查
if (config('wechat.payment.debug')) { if (config('wechat.payment.debug')) {
return true; return true;
@ -884,7 +891,8 @@ class WechatService
/** /**
* 服务端查询H5订单支付是否成功 * 服务端查询H5订单支付是否成功
*/ */
public function serverH5OrderPaid($order_id){ public function serverH5OrderPaid($order_id)
{
//测试不检查 //测试不检查
if (config('wechat.payment.debug')) { if (config('wechat.payment.debug')) {
return true; return true;
@ -918,7 +926,8 @@ class WechatService
} }
//查询h5订单支付成功? //查询h5订单支付成功?
public function officialOrderPaid($orderid){ public function officialOrderPaid($orderid)
{
//测试不检查 //测试不检查
if (config('wechat.payment.debug')) { if (config('wechat.payment.debug')) {
return true; return true;
@ -1182,7 +1191,8 @@ class WechatService
public function agRecommendNotcie($param = []) public function agRecommendNotcie($param = [])
{ {
$template_id = config('wechat.tpls.ag_recommend_notice'); $template_id = config('wechat.tpls.ag_recommend_notice');
$path = 'pages/home/information?id='.$param['user_id'].'&channel='.((isset($param['channel']))?$param['channel']:'');; $path = 'pages/home/information?id=' . $param['user_id'] . '&channel=' . ((isset($param['channel'])) ? $param['channel'] : '');
;
$data = [ $data = [
'first' => $param['title'], 'first' => $param['title'],
'keyword1' => $param['host'], 'keyword1' => $param['host'],
@ -1216,7 +1226,8 @@ class WechatService
} }
/** 受邀请后,注册成功,提示邀请者 */ /** 受邀请后,注册成功,提示邀请者 */
public function beRecommendNotcie($user_id,$nickname,$title,$touser_openid){ public function beRecommendNotcie($user_id, $nickname, $title, $touser_openid)
{
$template_id = config('wechat.tpls.be_invite_succeed_notice'); $template_id = config('wechat.tpls.be_invite_succeed_notice');
$path = 'pages/home/information?id=' . $user_id; $path = 'pages/home/information?id=' . $user_id;
$data = [ $data = [
@ -1230,7 +1241,8 @@ class WechatService
} }
/** 客服收到新消息 提示客服 */ /** 客服收到新消息 提示客服 */
public function remindServiceClient($user,$service){ public function remindServiceClient($user, $service)
{
$param['touser'] = $service->wechat ? $service->wechat->official_openid : null; $param['touser'] = $service->wechat ? $service->wechat->official_openid : null;
$name = $user->nickname ?: $user->name; $name = $user->nickname ?: $user->name;
// $param['template_id'] = config('wechat.tpls.activity_audited_notice'); // $param['template_id'] = config('wechat.tpls.activity_audited_notice');
@ -1349,7 +1361,8 @@ class WechatService
/** /**
* 发送模板消息 * 发送模板消息
*/ */
public function send($openid, $template_id, $page, $form_id,$data=[]){ public function send($openid, $template_id, $page, $form_id, $data = [])
{
try { try {
$all_data = [ $all_data = [
'touser' => $openid, 'touser' => $openid,
@ -1488,7 +1501,8 @@ class WechatService
} }
//拼团开始通知(发给团长的通知) //拼团开始通知(发给团长的通知)
public function stratGroupNotice($param){ public function stratGroupNotice($param)
{
$template_id = config('wechat.sub_tpls.start_group_notice'); $template_id = config('wechat.sub_tpls.start_group_notice');
$page = "pages/party/SpellGroupOrder?order_id=" . $param['order_id']; $page = "pages/party/SpellGroupOrder?order_id=" . $param['order_id'];
$time = date('Y-m-d H:i:s'); $time = date('Y-m-d H:i:s');
@ -1505,7 +1519,8 @@ class WechatService
public function subSendV2($openid, $template_id, $page, $data = []) public function subSendV2($openid, $template_id, $page, $data = [])
{ {
try { try {
if (empty($openid)) return false; if (empty($openid))
return false;
$all_data = [ $all_data = [
'template_id' => $template_id, 'template_id' => $template_id,
'touser' => $openid, 'touser' => $openid,
@ -1583,7 +1598,8 @@ class WechatService
public function subSend($openid, $template_id, $page, $data = []) public function subSend($openid, $template_id, $page, $data = [])
{ {
try { try {
if (empty($openid)) return false; if (empty($openid))
return false;
$all_data = [ $all_data = [
'template_id' => $template_id, 'template_id' => $template_id,
'touser' => $openid, 'touser' => $openid,
@ -1628,7 +1644,8 @@ class WechatService
/** /**
* 获取关注公众号的用户列表 * 获取关注公众号的用户列表
*/ */
public function getOfficialAccountsUserOpenId(){ public function getOfficialAccountsUserOpenId()
{
$result = $this->official_app->user->list(); $result = $this->official_app->user->list();
if (!empty($result) && !empty($result['data']['openid'])) { if (!empty($result) && !empty($result['data']['openid'])) {
$redis = Redis::connection('big_data'); $redis = Redis::connection('big_data');
@ -1660,7 +1677,8 @@ class WechatService
* @param $receivers * @param $receivers
* @param $sub_merchant_id * @param $sub_merchant_id
*/ */
public function wechatShare($transaction_id,$out_trade_no,$receivers,$sub_merchant_id){ public function wechatShare($transaction_id, $out_trade_no, $receivers, $sub_merchant_id)
{
$config = config('wechat.service_payment'); $config = config('wechat.service_payment');
$config['cert_path'] = storage_path('wechat/service-cert.pem'); $config['cert_path'] = storage_path('wechat/service-cert.pem');
$config['key_path'] = storage_path('wechat/service-key.pem'); $config['key_path'] = storage_path('wechat/service-key.pem');
@ -1681,7 +1699,8 @@ class WechatService
* @param $receivers * @param $receivers
* @param $sub_merchant_id * @param $sub_merchant_id
*/ */
public function wechatMultiShare($transaction_id,$out_trade_no,$receivers,$sub_merchant_id){ public function wechatMultiShare($transaction_id, $out_trade_no, $receivers, $sub_merchant_id)
{
$config = config('wechat.service_payment'); $config = config('wechat.service_payment');
$config['cert_path'] = storage_path('wechat/service_cert.pem'); $config['cert_path'] = storage_path('wechat/service_cert.pem');
$config['key_path'] = storage_path('wechat/service_key.pem'); $config['key_path'] = storage_path('wechat/service_key.pem');
@ -1704,7 +1723,8 @@ class WechatService
* @throws EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException * @throws \GuzzleHttp\Exception\GuzzleException
*/ */
public function addReceivers($receiver,$sub_merchant_id){ public function addReceivers($receiver, $sub_merchant_id)
{
$config = config('wechat.service_payment'); $config = config('wechat.service_payment');
$payment = Factory::payment($config); $payment = Factory::payment($config);
$payment->setSubMerchant($sub_merchant_id); $payment->setSubMerchant($sub_merchant_id);
@ -1722,7 +1742,8 @@ class WechatService
* @param $out_trade_no //商户分账单号,即商户订单号 * @param $out_trade_no //商户分账单号,即商户订单号
* @param $sub_merchant_id * @param $sub_merchant_id
*/ */
public function markOrderAsFinished($transaction_id,$out_trade_no,$sub_merchant_id){ public function markOrderAsFinished($transaction_id, $out_trade_no, $sub_merchant_id)
{
$config = config('wechat.service_payment'); $config = config('wechat.service_payment');
$config['cert_path'] = storage_path('wechat/service-cert.pem'); $config['cert_path'] = storage_path('wechat/service-cert.pem');
$config['key_path'] = storage_path('wechat/service-key.pem'); $config['key_path'] = storage_path('wechat/service-key.pem');
@ -1747,7 +1768,8 @@ class WechatService
* @param $out_trade_no //商户分账单号,即商户订单号 * @param $out_trade_no //商户分账单号,即商户订单号
* @param $sub_merchant_id * @param $sub_merchant_id
*/ */
public function wechatShareQuery($transaction_id,$out_trade_no,$sub_merchant_id){ public function wechatShareQuery($transaction_id, $out_trade_no, $sub_merchant_id)
{
$config = config('wechat.service_payment'); $config = config('wechat.service_payment');
$payment = Factory::payment($config); $payment = Factory::payment($config);
$payment->setSubMerchant($sub_merchant_id); $payment->setSubMerchant($sub_merchant_id);
@ -1781,7 +1803,8 @@ class WechatService
try { try {
$resp = $this->instance $resp = $this->instance
->chain('v3/transfer/batches') ->chain('v3/transfer/batches')
->post(['json' => [ ->post([
'json' => [
'appid' => config('wechat.official_account.new.app_id'), 'appid' => config('wechat.official_account.new.app_id'),
'out_trade_no' => $trade_no, 'out_trade_no' => $trade_no,
'batch_name' => $batch_name, 'batch_name' => $batch_name,
@ -1790,7 +1813,8 @@ class WechatService
'total_num' => count($transfer_list), 'total_num' => count($transfer_list),
'transfer_detail_list' => $transfer_list, 'transfer_detail_list' => $transfer_list,
'transfer_scene_id' => '', 'transfer_scene_id' => '',
]]); ]
]);
} catch (\Exception $e) { } catch (\Exception $e) {
dd($e->getMessage()); dd($e->getMessage());
} }
@ -1812,7 +1836,8 @@ class WechatService
'json' => $params 'json' => $params
]); ]);
$res = json_decode($response->getBody(), true); $res = json_decode($response->getBody(), true);
if (isset($res['errcode']) && $res['errcode'] == 0) return $res['url_link']; if (isset($res['errcode']) && $res['errcode'] == 0)
return $res['url_link'];
throw new Exception("请求url link失败, " . $res['errmsg']); throw new Exception("请求url link失败, " . $res['errmsg']);
} }
@ -1823,7 +1848,8 @@ class WechatService
{ {
$instance = $this->paymentInstance(); $instance = $this->paymentInstance();
$resp = $instance->chain('v3/applyment4sub/applyment/') $resp = $instance->chain('v3/applyment4sub/applyment/')
->post(['json' => [ ->post([
'json' => [
'business_code' => $business_code, 'business_code' => $business_code,
'contact_info' => $contact_info, 'contact_info' => $contact_info,
'subject_info' => $subject_info, 'subject_info' => $subject_info,
@ -1831,7 +1857,8 @@ class WechatService
'settlement_info' => $settlement_info, 'settlement_info' => $settlement_info,
'bank_account_info' => $bank_account_info, 'bank_account_info' => $bank_account_info,
'addition_info' => $addition_info, 'addition_info' => $addition_info,
]]); ]
]);
return json_decode($resp->getBody()); return json_decode($resp->getBody());
} }
@ -1935,11 +1962,66 @@ class WechatService
'nonceStr' => Formatter::nonce(), 'nonceStr' => Formatter::nonce(),
'package' => 'prepay_id=' . $prepay_id, 'package' => 'prepay_id=' . $prepay_id,
]; ];
$params += ['paySign' => Rsa::sign( $params += [
'paySign' => Rsa::sign(
Formatter::joinedByLineFeed(...array_values($params)), Formatter::joinedByLineFeed(...array_values($params)),
$merchantPrivateKeyInstance $merchantPrivateKeyInstance
), 'signType' => 'RSA']; ),
'signType' => 'RSA'
];
return $params; return $params;
} }
public function officialUserTransferV3($withdraw)
{
try {
DB::beginTransaction();
Log::info("转账请求");
$url = config("app.url") . "/util/api/wechatpay/admin/mch/transfer";
$notify_url = config("app.url") . "/api/s/h5/communities/UserWithdrawal/callback";
Log::info("转账请求链接:" . $url);
$data = [
"trade_no" => $withdraw->trade_no,
"openid" => $withdraw->account,
"amount" => (int) ($withdraw->real_value * 100),
"remark" => "用户提现",
"notify_url" => $notify_url,
];
$token = TokenHelper::generate(auth()->id());
$header = [
'Authorization' => "Bearer " . $token,
'Content-Type' => 'application/json'
];
$options = [
RequestOptions::TIMEOUT => 3,
RequestOptions::HTTP_ERRORS => false,
RequestOptions::HEADERS => $header,
RequestOptions::QUERY => $data,
];
$client = new Client();
$response = $client->post($url, $options);
$content = $response->getBody();
$res = json_decode($content, true);
if ($res && isset($res['code'])) {
if ($res['code']) {
throw new Exception($res['message']);
}
} else {
throw new Exception("提现失败");
}
$package_info = $res["data"]["data"]["package_info"];
$withdraw->package_info = $package_info;
$withdraw->status = "wait_user_confirm";
$withdraw->save();
DB::commit();
return null;
} catch (Exception $e) {
DB::rollBack();
$this->getError($e);
return ["msg" => $e->getMessage(), "err_code_des" => ""];
}
}
} }