thirdpayment
elf 11 months ago
parent ff4bac896e
commit 6dcdb45938

@ -0,0 +1,140 @@
<?php
declare(strict_types=1);
namespace App\Controller\Payment;
use App\Exception\BusinessException;
use App\Helper\Redis;
use App\Helper\RedisKey;
use App\Helper\StringHelper;
use App\Model\Account;
use App\Model\BankCard;
use Hyperf\HttpServer\Contract\RequestInterface;
use App\Service\PaymentService;
use App\Service\RequestService;
use App\Service\UserService;
class AccountController extends AbstractController
{
private RequestService $requestService;
private UserService $userService;
private PaymentService $paymentService;
public function __construct(RequestService $requestService, PaymentService $paymentService, UserService $userService)
{
$this->requestService = $requestService;
$this->userService = $userService;
$this->paymentService = $paymentService;
}
private function createRequestLog($data) {
$params = [
'app_id' => '',
'data' => json_encode($data),
];
return $this->requestService->createRequestLog('', $params);
}
private function checkUser(RequestInterface $request) {
$token = $request->input('token');
if (empty($token)) {
throw new BusinessException('未登录');
}
$result = Redis::get(RedisKey::getUserTokenKey($token));
if (empty($result)) {
throw new BusinessException('未登录');
}
$userInfo = json_decode($result, true);
if (empty($userInfo)) {
throw new BusinessException('未登录');
}
return $userInfo;
}
public function register(RequestInterface $request)
{
$username = $request->input('username');
$password = $request->input('password');
if (strlen($username) < 6 || strlen($username) > 20) {
throw new BusinessException('账号必须为620位');
}
if (strlen($password) < 6 || strlen($password) > 20) {
throw new BusinessException('密码必须为620位');
}
$account = Account::where('username', $username)->first();
if (!empty($account)) {
throw new BusinessException('账号已存在');
}
$account = new Account();
$account->salt = StringHelper::getRandomString(6);
$account->username = $username;
$account->password = md5($password . $account->salt);
$account->save();
return $this->success();
}
public function login(RequestInterface $request)
{
$username = $request->input('username');
$password = $request->input('password');
$account = Account::where('username', $username)->first();
if (empty($account)) {
throw new BusinessException('账号或密码错误');
}
if (md5($password . $account->salt) != $account->password) {
throw new BusinessException('账号或密码错误');
}
$userInfo = json_encode(['userId' => $account->account_id]);
$token = StringHelper::getRandomString(16);
Redis::set(RedisKey::getUserTokenKey($token), $userInfo);
Redis::expire(RedisKey::getUserTokenKey($token), 3600);
return $this->success(['token' => $token]);
}
public function openAccount(RequestInterface $request)
{
$userInfo = $this->checkUser($request);
$requestLog = $this->createRequestLog(['userId' => 'ACT_' . $userInfo['userId']]);
$url = $this->userService->register($requestLog->getData(), $requestLog->app, $requestLog->request_token);
return $this->success(['url' => $url]);
}
public function bindCard(RequestInterface $request)
{
$userInfo = $this->checkUser($request);
$requestLog = $this->createRequestLog(['userId' => 'ACT_' . $userInfo['userId']]);
$url = $this->userService->bindCard($requestLog->getData(), $requestLog->app, $requestLog->request_token);
return $this->success(['url' => $url]);
}
public function transferPay(RequestInterface $request)
{
$userInfo = $this->checkUser($request);
$bankCard = BankCard::where('user_id', 'ACT_' . $userInfo['userId'])->first();
$requestLog = $this->createRequestLog([
'userId' => 'ACT_' . $userInfo['userId'],
'goodsName' => '充值',
'agreementNo' => $bankCard->agreement_no,
'notifyUrl' => 'http://www.baidu.com',
'returnUrl' => 'http://www.baidu.com',
'amount' => intval($request->input('amount') * 100),
'outOrderNo' => time() . rand(1000, 9999),
'validDate' => date('Y-m-d', time() + 12*3600),
'marketInfo' => [
'amount' => 0,
'remark' => 'test',
],
'splitInfoList' => [
[
'splitUserId' => 'RLX1990',
'sellerFlag' => 1,
'splitAmount' => 100,
'subOutOrderNo' => time() . rand(1000, 9999),
]
]
]);
$acsNo = $this->paymentService->transferPay($requestLog->getData(), $requestLog->app, $requestLog->request_token);
return $this->success(['acsNo' => $acsNo]);
}
}

@ -46,7 +46,11 @@ class NotifyController extends AbstractController
$userId = $requestLog->getDataValue('userId'); $userId = $requestLog->getDataValue('userId');
$appId = $requestLog->app_id; $appId = $requestLog->app_id;
$this->userService->rsyncUser($params['loginNo'], $appId, $userId); $source = 0;
if ($requestLog->request_uri == '/register-user') {
$source = 1;
}
$this->userService->rsyncUser($params['loginNo'], $appId, $userId, $source);
$result = $this->notify( $result = $this->notify(
$requestLog->getDataValue('notifyUrl'), $requestLog->getDataValue('notifyUrl'),

@ -57,8 +57,8 @@ class PaymentController extends AbstractController
public function unbindCard(RequestInterface $request) public function unbindCard(RequestInterface $request)
{ {
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class); [$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$data = $this->userService->unbindCard($data, $app); $this->userService->unbindCard($data, $app);
return $this->success($data); return $this->success();
} }
public function pwdForget(RequestInterface $request) public function pwdForget(RequestInterface $request)
@ -108,8 +108,8 @@ class PaymentController extends AbstractController
public function refundApply(RequestInterface $request) public function refundApply(RequestInterface $request)
{ {
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class); [$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$data = $this->paymentService->refundApply($data, $app); $this->paymentService->refundApply($data, $app);
return $this->success($data); return $this->success();
} }
public function refundConfirm(RequestInterface $request) public function refundConfirm(RequestInterface $request)
@ -122,8 +122,8 @@ class PaymentController extends AbstractController
public function refundCancel(RequestInterface $request) public function refundCancel(RequestInterface $request)
{ {
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class); [$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$data = $this->paymentService->refundApply($data, $app); $this->paymentService->refundApply($data, $app);
return $this->success($data); return $this->success();
} }
public function queryBindCards(RequestInterface $request) public function queryBindCards(RequestInterface $request)

@ -29,4 +29,8 @@ class RedisKey
public static function getRequestTokenKey($token) { public static function getRequestTokenKey($token) {
return 'request_token:' . $token; return 'request_token:' . $token;
} }
public static function getUserTokenKey($token) {
return 'user_token:' . $token;
}
} }

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace App\Model;
class Account extends Model
{
protected $table = 'accounts';
}

@ -212,7 +212,11 @@ class PaymentService extends AbstractService
$order->save(); $order->save();
$platformAccount = User::getPlatformAccount(); $platformAccount = User::getPlatformAccount();
$fee = $platformAccount ? floor($order->amount * 0.007) : 0; $feeRate = 0.007;
if ($user->source == 1) {
$feeRate = 0.0023;
}
$fee = $platformAccount ? floor($order->amount * $feeRate) : 0;
if ($fee <= 0) { if ($fee <= 0) {
$fee = 1; $fee = 1;
} }

@ -41,13 +41,13 @@ class UserService extends AbstractService
return $url; return $url;
} }
public function rsyncUser($memberId, $appId, $userId) { public function rsyncUser($memberId, $appId, $userId, $source = 0) {
$baofu = new Baofu(); $baofu = new Baofu();
$userInfo = $baofu->queryCustomerInfo($memberId); $userInfo = $baofu->queryCustomerInfo($memberId);
return $this->saveUser($userInfo, $appId, $userId); return $this->saveUser($userInfo, $appId, $userId, $source);
} }
public function saveUser($userInfo, $appId, $userId) { public function saveUser($userInfo, $appId, $userId, $source = 0) {
$memberId = $userInfo['loginNo'] ?? $userInfo['loginMobile']; $memberId = $userInfo['loginNo'] ?? $userInfo['loginMobile'];
$user = User::where('app_id', $appId)->where('member_id', $memberId)->first(); $user = User::where('app_id', $appId)->where('member_id', $memberId)->first();
if ($user) { if ($user) {
@ -62,6 +62,7 @@ class UserService extends AbstractService
$user->certificate_no = $userInfo['certificateNo'] ?? ''; $user->certificate_no = $userInfo['certificateNo'] ?? '';
$user->user_type = $userInfo['customerType']; $user->user_type = $userInfo['customerType'];
$user->apply_no = $userInfo['applyNo'] ?? ''; $user->apply_no = $userInfo['applyNo'] ?? '';
$user->source = $source;
} else { } else {
$user = new User(); $user = new User();
$user->user_id = $userId; $user->user_id = $userId;
@ -78,6 +79,7 @@ class UserService extends AbstractService
$user->certificate_no = $userInfo['certificateNo'] ?? ''; $user->certificate_no = $userInfo['certificateNo'] ?? '';
$user->user_type = $userInfo['customerType']; $user->user_type = $userInfo['customerType'];
$user->apply_no = $userInfo['applyNo'] ?? ''; $user->apply_no = $userInfo['applyNo'] ?? '';
$user->source = $source;
} }
$user->save(); $user->save();
return $user; return $user;

@ -2,6 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
use App\Controller\Payment\AccountController;
use App\Controller\Payment\NotifyController; use App\Controller\Payment\NotifyController;
use App\Controller\Payment\PaymentController; use App\Controller\Payment\PaymentController;
use App\Controller\Payment\ReturnController; use App\Controller\Payment\ReturnController;
@ -36,6 +37,14 @@ Router::addGroup('/payment',function () {
Router::post('/query-sign-entrust', [PaymentController::class, 'querySignEntrust']); Router::post('/query-sign-entrust', [PaymentController::class, 'querySignEntrust']);
}, ['middleware' => [\App\Middleware\RequestLogMiddleware::class, \App\Middleware\AppAuthMiddleWare::class]]); }, ['middleware' => [\App\Middleware\RequestLogMiddleware::class, \App\Middleware\AppAuthMiddleWare::class]]);
Router::addGroup('/account',function () {
Router::post('/login', [AccountController::class, 'login']);
Router::post('/register', [AccountController::class, 'register']);
Router::post('/open-account', [AccountController::class, 'openAccount']);
Router::post('/bind-card', [AccountController::class, 'bindCard']);
Router::post('/transfer-pay', [AccountController::class, 'transferPay']);
}, []);
Router::addGroup('/notify',function () { Router::addGroup('/notify',function () {
Router::addRoute(['GET', 'POST'], '/register/{token}', [NotifyController::class, 'register']); Router::addRoute(['GET', 'POST'], '/register/{token}', [NotifyController::class, 'register']);
Router::addRoute(['GET', 'POST'], '/bind-card/{token}', [NotifyController::class, 'bindCard']); Router::addRoute(['GET', 'POST'], '/bind-card/{token}', [NotifyController::class, 'bindCard']);

@ -0,0 +1,119 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- import CSS -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<title>我的账户</title>
</head>
<body>
<div id="app">
<el-container>
<el-main>
<el-row>
<el-col :span="24">
<el-descriptions title="用户信息">
<el-descriptions-item label="用户名">kooriookami</el-descriptions-item>
<el-descriptions-item label="手机号">18100000000</el-descriptions-item>
<el-descriptions-item label="居住地">苏州市</el-descriptions-item>
<el-descriptions-item label="备注">
<el-tag size="small">学校</el-tag>
</el-descriptions-item>
<el-descriptions-item label="联系地址">江苏省苏州市吴中区吴中大道 1188 号</el-descriptions-item>
</el-descriptions>
</el-col>
</el-row>
</el-main>
</el-container>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://unpkg.com/axios@1.1.2/dist/axios.min.js"></script>
<script>
new Vue({
el: '#app',
data() {
return {
activeName: 'register',
loginForm: {
username: '',
password: ''
},
registerForm: {
username: '',
password: '',
confirm_password: ''
}
}
},
created() {
if (!window.sessionStorage.getItem('token')) {
window.location.href = '/login.html'
return;
}
},
methods: {
bindCard() {
axios.post('/account/bind-card', this.bindConfirmForm)
.then( (response) => {
console.log(response);
let result = response.data
if (result.code != 1000) {
return this.$message.error(response.data.message);
}
this.bindConfirmVisible = false;
this.$message.success('支付成功');
this.$alert('请记住您的订单号:' + result.data.bizData.outOrderNo , '支付成功', {
confirmButtonText: '确定',
callback: action => {
}
});
})
.catch((error) => {
this.$message.error('请求错误');
console.log(error);
});
console.log('submit!');
},
transferPay() {
axios.post('/account/transfer-pay', this.payConfirmForm)
.then( (response) => {
console.log(response);
let result = response.data
if (result.code != 1000) {
return this.$message.error(response.data.message);
}
this.payConfirmVisible = false;
this.$message.success('支付成功');
this.$alert('请记住您的订单号:' + result.data.bizData.outOrderNo , '支付成功', {
confirmButtonText: '确定',
callback: action => {
}
});
})
.catch((error) => {
this.$message.error('请求错误');
console.log(error);
});
console.log('submit!');
},
getQueryParam(name) {
var query = window.location.search.substring(1);
console.log(query)
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
console.log(pair[0], name)
if(pair[0] == name) {
return pair[1];
}
}
return undefined;
}
}
})
</script>
</html>

@ -0,0 +1,129 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- import CSS -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<title>支付系统</title>
</head>
<body>
<div id="app">
<el-container>
<el-main>
<el-row>
<el-col :span="24">
<el-tabs v-model="activeName">
<el-tab-pane label="注册" name="register">
<el-form ref="registerForm" :model="registerForm" label-width="80px">
<el-form-item label="账号">
<el-input v-model="registerForm.username"></el-input>
</el-form-item>
<el-form-item label="密码">
<el-input show-password v-model="registerForm.password"></el-input>
</el-form-item>
<el-form-item label="确认密码">
<el-input show-password v-model="registerForm.confirm_password"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="register">注册</el-button>
</el-form-item>
</el-form>
</el-tab-pane>
<el-tab-pane label="登录" name="login">
<el-form ref="loginForm" :model="loginForm" label-width="80px">
<el-form-item label="账号">
<el-input v-model="loginForm.username"></el-input>
</el-form-item>
<el-form-item label="密码">
<el-input show-password v-model="loginForm.password"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="register">登录</el-button>
</el-form-item>
</el-form>
</el-tab-pane>
</el-tabs>
</el-col>
</el-row>
</el-main>
</el-container>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://unpkg.com/axios@1.1.2/dist/axios.min.js"></script>
<script>
new Vue({
el: '#app',
data() {
return {
activeName: 'register',
loginForm: {
username: '',
password: ''
},
registerForm: {
username: '',
password: '',
confirm_password: ''
}
}
},
created() {
if (window.sessionStorage.getItem('token')) {
window.location.href = '/account.html'
return;
}
},
methods: {
register() {
axios.post('/account/register', this.registerForm)
.then( (response) => {
console.log(response);
let result = response.data
if (result.code != 1000) {
return this.$message.error(response.data.message);
}
this.activeName = 'login';
})
.catch((error) => {
this.$message.error('请求错误');
console.log(error);
});
console.log('submit!');
},
login() {
axios.post('/account/login', this.loginForm)
.then( (response) => {
console.log(response);
let result = response.data
if (result.code != 1000) {
return this.$message.error(response.data.message);
}
window.sessionStorage.setItem('token', result.data.token)
})
.catch((error) => {
this.$message.error('请求错误');
console.log(error);
});
console.log('submit!');
},
getQueryParam(name) {
var query = window.location.search.substring(1);
console.log(query)
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
console.log(pair[0], name)
if(pair[0] == name) {
return pair[1];
}
}
return undefined;
}
}
})
</script>
</html>
Loading…
Cancel
Save