转账功能优化
This commit is contained in:
@@ -10,18 +10,22 @@ use app\common\service\AccountWithdrawService;
|
||||
use app\common\service\CategoryService;
|
||||
use app\common\service\DemandBiddingService;
|
||||
use app\common\service\DemandService;
|
||||
use app\common\service\EasyWeChatService;
|
||||
use app\common\service\GoodsService;
|
||||
use app\common\model\Category;
|
||||
use app\common\service\OrderService;
|
||||
use app\common\service\TransferAuthorizationService;
|
||||
use app\common\service\UserService;
|
||||
use EasyWeChat\Pay\Message as PayMessage;
|
||||
use fast\Tree;
|
||||
use think\Exception;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\Log;
|
||||
use think\Validate;
|
||||
|
||||
class Account extends Api
|
||||
{
|
||||
protected $noNeedLogin = [];
|
||||
protected $noNeedLogin = ['transferAuthorizationNotify'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
public function logs()
|
||||
@@ -94,4 +98,65 @@ class Account extends Api
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 免确认收款授权(发起/查询),供前端 wx.requestMerchantTransfer 拉起授权页
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function transferAuthorization()
|
||||
{
|
||||
try {
|
||||
$user_id = $this->auth->id ?? 0;
|
||||
if (!$user_id) {
|
||||
throw new \Exception('请先登录');
|
||||
}
|
||||
$user = UserService::get($user_id);
|
||||
if (!$user) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
//授权详情展示账号名:优先微信实名(提现填写的姓名),其次昵称
|
||||
$displayName = $user->username ?: ($user->nickname ?: '');
|
||||
$res = TransferAuthorizationService::apply($user, $displayName);
|
||||
|
||||
$this->success('', $res);
|
||||
} catch (\Exception $e) {
|
||||
if ($e instanceof HttpResponseException) {
|
||||
throw $e;
|
||||
}
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 免确认收款授权结果回调(微信异步通知,已加入 noNeedLogin)
|
||||
* @return void
|
||||
*/
|
||||
public function transferAuthorizationNotify()
|
||||
{
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
try {
|
||||
// PSR-7 响应(SDK 已完成验签/解密,业务失败返回 500 由微信重试)
|
||||
$response = (new EasyWeChatService())->handleTransferAuthorizationNotify(
|
||||
function (PayMessage $message) {
|
||||
TransferAuthorizationService::handleAuthorizationNotify($message->toArray());
|
||||
}
|
||||
);
|
||||
http_response_code($response->getStatusCode());
|
||||
foreach ($response->getHeaders() as $name => $values) {
|
||||
header($name . ': ' . implode(', ', $values));
|
||||
}
|
||||
$body = $response->getBody()->getContents();
|
||||
Log::info('免确认收款授权回调[应答] http_code=' . $response->getStatusCode() . ' body=' . $body);
|
||||
echo $body;
|
||||
exit;
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('免确认收款授权回调[异常]:' . json_encode([
|
||||
'msg' => $e->getMessage(),
|
||||
'file' => $e->getFile() . ':' . $e->getLine(),
|
||||
], JSON_UNESCAPED_UNICODE));
|
||||
http_response_code(500);
|
||||
echo json_encode(['code' => 'FAIL', 'message' => $e->getMessage()], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user