Compare commits
8 Commits
beede66837
...
87a311a800
Author | SHA1 | Date | |
---|---|---|---|
![]() |
87a311a800 | ||
![]() |
e561fae860 | ||
![]() |
c6e2c03617 | ||
![]() |
55b1247b27 | ||
![]() |
9e6afd0665 | ||
![]() |
602da1570b | ||
![]() |
c4ff4f2207 | ||
![]() |
7e26e15c12 |
@ -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' => '暂无订单数据'));
|
||||
|
@ -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 {
|
||||
//数据库写入失败
|
||||
|
@ -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();
|
||||
|
@ -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 位替换成星号
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user