Compare commits

...

8 Commits

Author SHA1 Message Date
tk
87a311a800 【类 型】:fix
【主	题】:写入数据库字段 键值修改
【描	述】:
	[原因]:因订单表字段修改 写入数据库 键值修改
	[过程]:创建订单时间 addtime改为 order_time
	[影响]:
【结	束】

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
2024-06-20 19:41:35 +08:00
tk
e561fae860 【类 型】:fix
【主	题】:支付接口 检查前端提交数据
【描	述】:
	[原因]:支付前 从后端取数据检测 提高安全性
	[过程]:
	[影响]:
【结	束】

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
2024-06-20 19:23:40 +08:00
tk
c6e2c03617 【类 型】:style
【主	题】:冗余 引用
【描	述】:
	[原因]:
	[过程]:
	[影响]:
【结	束】

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
2024-06-20 18:39:58 +08:00
tk
55b1247b27 【类 型】:fix
【主	题】:写入数据库字段 键值修改
【描	述】:
	[原因]:因订单表字段修改 写入数据库 键值修改
	[过程]:
	[影响]:
【结	束】

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
2024-06-20 18:22:10 +08:00
tk
9e6afd0665 【类 型】:refactor
【主	题】:修改maketkoen 函数 及之前的调用
【描	述】:
	[原因]:之前只能指定参数 指定字段,改为数组来传,方便灵活
	[过程]:改成输出传值
	[影响]:
【结	束】

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
2024-06-20 17:25:59 +08:00
tk
602da1570b 【类 型】:refactor
【主	题】:更改订单字段的长度 取消年的前两位  后缀随机加三位
【描	述】:
	[原因]:
	[过程]:
	[影响]:
【结	束】

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
2024-06-20 16:01:41 +08:00
tk
c4ff4f2207 Merge branch 'master' of http://111.229.174.37:3000/Food/food_server 2024-06-19 19:59:55 +08:00
tk
7e26e15c12 【类 型】:fix
【主	题】:跨域 请求头报错  状态码500
【描	述】:
	[原因]:反复请求接口会出问题
	[过程]:重新设置请求方法 请求头
	[影响]:
【结	束】

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
2024-06-17 18:11:15 +08:00
5 changed files with 57 additions and 34 deletions

View File

@ -110,7 +110,7 @@ class CheckController extends PublicController
// 创建订单
$data['shop_id'] = $_REQUEST['shop_id'];
$data['order_sn'] = date('ymdHi') . str_pad(mt_rand(1, 9999), 4, '0', STR_PAD_LEFT);
$data['order_sn'] = date('y') . date('mdHi') . str_pad(mt_rand(1, 999), 3, '0', STR_PAD_LEFT);
$data['total_weight'] = $total_weight;
$data['total_price'] = $total_price;
$data['total_num'] = $total_num;
@ -136,7 +136,7 @@ class CheckController extends PublicController
$data['receive_site_name'] = $site['sitename'];
$data['product_snapshot'] = json_encode($product_snapshot, JSON_UNESCAPED_UNICODE);
$data['remark'] = $_REQUEST['remark'];
$data['addtime'] = time();
$data['order_time'] = time();
$orderDb = D('order');
$isAdd = $orderDb->data($data)->add();
@ -152,10 +152,11 @@ class CheckController extends PublicController
*/
public function getOrderList()
{
$field = array('order_sn,food_sn,total_weight,total_num,total_price,refund_price,receiver,tel,receive_site_id,receive_site_name,remark,product_snapshot,main_status,shipment_status,back_status,back_remark,back_time,back_addtime,addtime');
$where['openid'] = $this->openid;
$where['status'] = array('neq', 'canceled'); //排除已取消的订单
$orderDb = D('order');
if ($orderList = $orderDb->where($where)->select()) {
if ($orderList = $orderDb->where($where)->field($field)->select()) {
echo json_encode(array('status' => 1, 'msg' => '访问成功', "orderList" => $orderList));
} else {
echo json_encode(array('status' => 0, 'msg' => '暂无订单数据'));

View File

@ -56,7 +56,7 @@ class LoginController extends PublicController
if ($id = $userDb->data($data)->add()) {
$user = $userDb->find($id); //获取刚刚插入的记录
//分发token等用户信息给前端
$token = $this->makeToken($getAuth['openid'], $getAuth['session_key']);
$token = $this->makeToken(array('openid' => $getAuth['openid'], 'session_key' => $getAuth['session_key']));
$userInfo = array('token' => $token, 'name' => $user['name'], 'photo' => $user['photo'], 'sex' => $user['sex'], 'tel' => $user['tel'], 'topic_prefix' => makeTopicPrefix($getAuth['openid']));
} else {
//数据库写入失败

View File

@ -3,9 +3,6 @@
namespace Api\Controller;
use Yansongda\Pay\Pay;
use PhpMqtt\Client\MqttClient;
use PhpMqtt\Client\Exceptions\MqttClientException;
use PhpMqtt\Client\ConnectionSettings;
class PayController extends PublicController
{
@ -56,12 +53,30 @@ class PayController extends PublicController
//获取订单信息
$where['order_sn'] = $_REQUEST['order_sn'];
$field = array('order_sn,shop_id,total_price,total_weight,openid');
$orderDb = D('order');
if ($order = $orderDb->where($where)->field($field)->find()) {
echo json_encode(array('status' => 0, 'msg' => '订单不存在'));
exit();
}
//订单检查
$whereShop['shop_id'] = $order['shop_id'];
$fieldShop = array('price_min', 'weight_max');
$shopDb = D('shop');
if ($shop = $shopDb->where($whereShop)->field($fieldShop)->find()) {
echo json_encode(array('status' => 0, 'msg' => '商铺不存在'));
exit();
}
if ($order['openid'] != $this->openid || (float)$order['total_price'] < (float)$shop['price_min'] || $order['total_weight'] > $shop['weight_max']) {
echo json_encode(array('status' => 0, 'msg' => '提交信息异常'));
exit();
}
$orderDb = D('order');
$order = $orderDb->where($where)->find();
//设置获取签名的订单参数
$orderParameter = [
'out_trade_no' => $order['order_sn'],
'description' => $order['shop_id'], //这个字段用 商铺id 方便分类查询腾讯的支付订单,还有在回调时候发送“订单更新主题”的子主题区分
'description' => $order['shop_id'], //用jwt加密 shop_id商铺id 存放
'amount' => [
'total' => $order['total_price'] * 100, //单位:分
'currency' => 'CNY',
@ -86,13 +101,13 @@ class PayController extends PublicController
// 实例化 Yansongda Pay
$result = Pay::wechat($this->config)->callback();
$this->publish('refreshQuestList/2dc23dcfecc05fb1', 1);
try {
// 验证成功,处理业务逻辑
if ($result['resource']['ciphertext']['trade_state'] == 'SUCCESS') {
$where['order_sn'] = $result['resource']['ciphertext']['out_trade_no']; // 获取订单号
$orderDb = D('order'); // 实例化订单模型
$data['status'] = 'pending'; // 更新订单状态为已支付
$data['status'] = '已付款'; // 更新订单状态为已支付
$data['paid_time'] = time(); //标记付款时间
$data['pay_sn'] = $result['resource']['ciphertext']['transaction_id']; // 支付订单号
// 更新订单
$orderDb->where($where)->data($data)->save();

View File

@ -57,25 +57,29 @@ class PublicController extends Controller
}
/**
* @description: 构建token
* @param {*} openid 微信用户唯一凭证
* @param {array} data 要存储在 JWT 中的数据,键值对形式 ps:这里可以传exp 来覆盖默认的过期时间
* @return {*} token
*/
protected function makeToken($openid, $session_key)
protected function makeToken($data = [])
{
// 定义密钥,应该使用安全的随机字符串并妥善保管
$jwtKey = C('jwtKey');
$currtime = time();
// 要存储在 JWT 中的数据
$data = [
'iat' => $currtime, // 签发时间(时间戳)
// 默认的数据
$defaultData = [
'iat' => $currtime, // 签发时间(时间戳)
'iss' => 'jwt_admin', // 签发者
'nbf' => $currtime, // 在此时间之前不可用 (这里是2秒以内)
'nbf' => $currtime, // 在此时间之前不可用 (这里是2秒以内)
'exp' => strtotime('tomorrow'), //过期时间 到第二天凌晨
'openid' => $openid,
'session_key' => $session_key,
'jti' => md5(uniqid('JWT') . $currtime), // JWT ID令牌的唯一标识符
];
// 合并默认数据和传递的数据
$tokenData = array_merge($defaultData, $data);
// 使用密钥和 HS256 算法对数据进行编码生成 JWT
return JWT::encode($data, $jwtKey, 'HS256');
return JWT::encode($tokenData, $jwtKey, 'HS256');
}
/**
* @description: 将手机号的倒数第 5 位到第 8 位替换成星号

View File

@ -50,7 +50,7 @@ class LoginController extends Controller
//删除多余信息
unset($adminInfo['pwd']);
//创建token
$token = $this->makeToken();
$token = $this->makeToken(array('shop_id' => $this->shop_id));
//登陆成功 返回token
echo json_encode(array('status' => 1, 'msg' => '登陆成功', 'adminInfo' => $adminInfo, 'token' => $token), JSON_UNESCAPED_UNICODE);
} else {
@ -65,24 +65,27 @@ class LoginController extends Controller
}
}
/**
* @Description: 构建token
* @Return: token
* @description: 构建token
* @param {array} data 要存储在 JWT 中的数据,键值对形式 ps:这里可以传exp 来覆盖默认的过期时间
* @return {*} token
*/
private function makeToken()
private function makeToken($data = [])
{
$jwtKey = C('jwtKey'); // jwt密钥
$currtime = time();
// 要存储在 JWT 中的数据
$data = [
'iat' => $currtime, // 签发时间(时间戳)
'iss' => 'jwt_admin', // 签发者
'nbf' => $currtime, // 在此时间之前不可用 (这里是2秒以内)
'exp' => strtotime('tomorrow'), //过期时间 到第二天凌晨
'jti' => md5(uniqid('JWT') . $currtime),
'sub' => 'http://localhost:8080',
'shop_id' => $this->shop_id,
// 默认的数据
$defaultData = [
'iat' => $currtime, // 签发时间(时间戳)
'iss' => 'jwt_admin', // 签发者
'nbf' => $currtime, // 在此时间之前不可用 (这里是2秒以内)
'exp' => strtotime('tomorrow'), //过期时间 到第二天凌晨
'jti' => md5(uniqid('JWT') . $currtime), // JWT ID令牌的唯一标识符
];
// 合并默认数据和传递的数据
$tokenData = array_merge($defaultData, $data);
// 使用密钥和 HS256 算法对数据进行编码生成 JWT
return JWT::encode($data, $jwtKey, 'HS256');
return JWT::encode($tokenData, $jwtKey, 'HS256');
}
}