Compare commits

..

No commits in common. "87a311a800c6b4d6de119e6333a5739e22f9c6a5" and "beede66837b08ed9c73b988d0ee4069c972f3ea1" have entirely different histories.

5 changed files with 34 additions and 57 deletions

View File

@ -110,7 +110,7 @@ class CheckController extends PublicController
// 创建订单
$data['shop_id'] = $_REQUEST['shop_id'];
$data['order_sn'] = date('y') . date('mdHi') . str_pad(mt_rand(1, 999), 3, '0', STR_PAD_LEFT);
$data['order_sn'] = date('ymdHi') . str_pad(mt_rand(1, 9999), 4, '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['order_time'] = time();
$data['addtime'] = time();
$orderDb = D('order');
$isAdd = $orderDb->data($data)->add();
@ -152,11 +152,10 @@ 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)->field($field)->select()) {
if ($orderList = $orderDb->where($where)->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(array('openid' => $getAuth['openid'], 'session_key' => $getAuth['session_key']));
$token = $this->makeToken($getAuth['openid'], $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,6 +3,9 @@
namespace Api\Controller;
use Yansongda\Pay\Pay;
use PhpMqtt\Client\MqttClient;
use PhpMqtt\Client\Exceptions\MqttClientException;
use PhpMqtt\Client\ConnectionSettings;
class PayController extends PublicController
{
@ -53,30 +56,12 @@ 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'], //用jwt加密 shop_id商铺id 存放
'description' => $order['shop_id'], //这个字段用 商铺id 方便分类查询腾讯的支付订单,还有在回调时候发送“订单更新主题”的子主题区分
'amount' => [
'total' => $order['total_price'] * 100, //单位:分
'currency' => 'CNY',
@ -101,13 +86,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'] = '已付款'; // 更新订单状态为已支付
$data['paid_time'] = time(); //标记付款时间
$data['status'] = 'pending'; // 更新订单状态为已支付
$data['pay_sn'] = $result['resource']['ciphertext']['transaction_id']; // 支付订单号
// 更新订单
$orderDb->where($where)->data($data)->save();

View File

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

View File

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