Compare commits
2 Commits
e8f9a1cb4d
...
a736bc7b92
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a736bc7b92 | ||
![]() |
c60e68348f |
@ -61,7 +61,7 @@ class PayController extends PublicController
|
|||||||
//设置获取签名的订单参数
|
//设置获取签名的订单参数
|
||||||
$orderParameter = [
|
$orderParameter = [
|
||||||
'out_trade_no' => $order['order_sn'],
|
'out_trade_no' => $order['order_sn'],
|
||||||
'description' => $order['shop_id'], //商品名称
|
'description' => $order['shop_id'], //这个字段用 商铺id 方便分类查询腾讯的支付订单,还有在回调时候发送“订单更新主题”的子主题区分
|
||||||
'amount' => [
|
'amount' => [
|
||||||
'total' => $order['total_price'] * 100, //单位:分
|
'total' => $order['total_price'] * 100, //单位:分
|
||||||
'currency' => 'CNY',
|
'currency' => 'CNY',
|
||||||
@ -85,7 +85,7 @@ class PayController extends PublicController
|
|||||||
{
|
{
|
||||||
// 实例化 Yansongda Pay
|
// 实例化 Yansongda Pay
|
||||||
$result = Pay::wechat($this->config)->callback();
|
$result = Pay::wechat($this->config)->callback();
|
||||||
// 地面终端 和 小程序端的提示刷新信息
|
|
||||||
$this->publish('refreshQuestList/2dc23dcfecc05fb1', 1);
|
$this->publish('refreshQuestList/2dc23dcfecc05fb1', 1);
|
||||||
try {
|
try {
|
||||||
// 验证成功,处理业务逻辑
|
// 验证成功,处理业务逻辑
|
||||||
@ -97,6 +97,9 @@ class PayController extends PublicController
|
|||||||
// 更新订单
|
// 更新订单
|
||||||
$orderDb->where($where)->data($data)->save();
|
$orderDb->where($where)->data($data)->save();
|
||||||
}
|
}
|
||||||
|
// 构建发布主题 并向地面终端提示刷新信息
|
||||||
|
$topic = 'refreshQuestList/' . $result['resource']['ciphertext']['description'];
|
||||||
|
$this->publish($topic, 1);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// 捕获并记录可能的异常
|
// 捕获并记录可能的异常
|
||||||
error_log('支付回调处理错误:' . $e->getMessage());
|
error_log('支付回调处理错误:' . $e->getMessage());
|
||||||
|
@ -9,7 +9,3 @@ function makeTopicPrefix($openid)
|
|||||||
{
|
{
|
||||||
return substr(md5($openid . date("j")), 0, 8); //用户id+当天日 加密 截取前8位
|
return substr(md5($openid . date("j")), 0, 8); //用户id+当天日 加密 截取前8位
|
||||||
}
|
}
|
||||||
function demo()
|
|
||||||
{
|
|
||||||
echo "hello";
|
|
||||||
}
|
|
||||||
|
@ -8,7 +8,6 @@ class IndexController extends Controller
|
|||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
demo();
|
|
||||||
$this->display();
|
$this->display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,10 @@ namespace MpApi\Controller;
|
|||||||
use Think\Image;
|
use Think\Image;
|
||||||
use Org\ImageController\ImageController;
|
use Org\ImageController\ImageController;
|
||||||
|
|
||||||
|
use PhpMqtt\Client\MqttClient;
|
||||||
|
use PhpMqtt\Client\Exceptions\MqttClientException;
|
||||||
|
use PhpMqtt\Client\ConnectionSettings;
|
||||||
|
|
||||||
class PlaneController extends PublicController
|
class PlaneController extends PublicController
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
@ -571,7 +575,10 @@ class PlaneController extends PublicController
|
|||||||
} elseif ($_REQUEST['state'] == 'back') {
|
} elseif ($_REQUEST['state'] == 'back') {
|
||||||
$data['back'] = $_REQUEST['val']; //改变订单状态
|
$data['back'] = $_REQUEST['val']; //改变订单状态
|
||||||
}
|
}
|
||||||
if ($orderDb->where($where)->save($data)) {
|
if ($orderDb->where($where)->save($data)) { //修改数据
|
||||||
|
$topicPrefix = makeTopicPrefix($order['openid']); //小程序端用户订阅主题的前缀 ps:订单对应的用户的openid算出来的
|
||||||
|
// 提醒小程序端 刷新订单列表
|
||||||
|
$this->publish('refreshOrderList/' . $topicPrefix, 1);
|
||||||
echo json_encode(array('status' => 1, 'msg' => '订单修改成功'));
|
echo json_encode(array('status' => 1, 'msg' => '订单修改成功'));
|
||||||
} else {
|
} else {
|
||||||
echo json_encode(array('status' => 0, 'msg' => '订单修改失败'));
|
echo json_encode(array('status' => 0, 'msg' => '订单修改失败'));
|
||||||
|
@ -6,6 +6,10 @@ use Think\Controller;
|
|||||||
use Firebase\JWT\JWT;
|
use Firebase\JWT\JWT;
|
||||||
use Firebase\JWT\Key;
|
use Firebase\JWT\Key;
|
||||||
|
|
||||||
|
use PhpMqtt\Client\MqttClient;
|
||||||
|
use PhpMqtt\Client\Exceptions\MqttClientException;
|
||||||
|
use PhpMqtt\Client\ConnectionSettings;
|
||||||
|
|
||||||
class PublicController extends Controller
|
class PublicController extends Controller
|
||||||
{
|
{
|
||||||
//****************
|
//****************
|
||||||
@ -148,4 +152,37 @@ class PublicController extends Controller
|
|||||||
echo json_encode(array('status' => 0, 'msg' => '登录异常'));
|
echo json_encode(array('status' => 0, 'msg' => '登录异常'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @description: 连接mqtt服务器 并向指定主题发布信息
|
||||||
|
* @param string $topic mqtt主题
|
||||||
|
* @param string $msg 要发布的主题
|
||||||
|
*/
|
||||||
|
protected function publish($topic, $msg)
|
||||||
|
{
|
||||||
|
$server = C('mqtt')['server']; // MQTT 代理地址
|
||||||
|
$port = C('mqtt')['port']; // MQTT 代理端口
|
||||||
|
$clientId = C('mqtt')['client_id']; // 客户端 ID
|
||||||
|
$username = C('mqtt')['username']; // 用户名(如果需要)
|
||||||
|
$password = C('mqtt')['password']; // 密码(如果需要)
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 创建连接设置对象
|
||||||
|
$settings = (new ConnectionSettings)->setUsername($username)->setPassword($password);
|
||||||
|
// 实例化 MQTT 客户端
|
||||||
|
$mqtt = new MqttClient($server, $port, $clientId);
|
||||||
|
// 连接到 MQTT 代理
|
||||||
|
$mqtt->connect($settings);
|
||||||
|
// 检查是否连接成功
|
||||||
|
if ($mqtt->isConnected()) {
|
||||||
|
// 发布消息到指定的主题 ps:主题 信息 qos
|
||||||
|
$mqtt->publish($topic, $msg, 0);
|
||||||
|
// 断开连接
|
||||||
|
$mqtt->disconnect();
|
||||||
|
} else {
|
||||||
|
echo "连接失败";
|
||||||
|
}
|
||||||
|
} catch (MqttClientException $e) { //连接失败
|
||||||
|
echo "Could not connect to MQTT broker: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user