作者 郭文星

123

... ... @@ -26,7 +26,7 @@ class WxxcxPush extends Base
public function sendDealApplyMessage($openid_arr, $apply_info)
{
if (empty($openid_arr)) {
return array_callback(false, "未找到需要推送的人员");
return $this->array_callback(false, "未找到需要推送的人员");
}
$sum_count = 0;//总共需要推送的人
$react_count = 0;//实际推送人数
... ... @@ -90,15 +90,15 @@ class WxxcxPush extends Base
// 执行提交操作
Db::commit();
return array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]);
return $this->array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]);
} catch (PDOException $e) {
Db::rollback();
return array_callback(false, "请求异常" . $e->getMessage());
return $this->array_callback(false, "请求异常" . $e->getMessage());
}
} else {
return array_callback(false, "未找到可通知的社区管理员!");
return $this->array_callback(false, "未找到可通知的社区管理员!");
}
... ... @@ -110,7 +110,7 @@ class WxxcxPush extends Base
public function sendDealSuccessMessage($openid_arr, $deal_info)
{
if (empty($openid_arr)) {
return array_callback(false, "未找到需要推送的人员");
return $this->array_callback(false, "未找到需要推送的人员");
}
$sum_count = 0;//总共需要推送的人
$react_count = 0;//实际推送人数
... ... @@ -168,15 +168,15 @@ class WxxcxPush extends Base
// 执行提交操作
Db::commit();
return array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]);
return $this->array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]);
} catch (PDOException $e) {
Db::rollback();
return array_callback(false, "请求异常" . $e->getMessage());
return $this->array_callback(false, "请求异常" . $e->getMessage());
}
} else {
return array_callback(false, "未找到可通知的申报用户!");
return $this->array_callback(false, "未找到可通知的申报用户!");
}
}
... ... @@ -187,7 +187,7 @@ class WxxcxPush extends Base
public function sendUploadReportMessage($openid_arr, $deal_info,$report)
{
if (empty($openid_arr)) {
return array_callback(false, "未找到需要推送的人员");
return $this->array_callback(false, "未找到需要推送的人员");
}
$sum_count = 0;//总共需要推送的人
$react_count = 0;//实际推送人数
... ... @@ -244,15 +244,15 @@ class WxxcxPush extends Base
// 执行提交操作
Db::commit();
return array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]);
return $this->array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]);
} catch (PDOException $e) {
Db::rollback();
return array_callback(false, "请求异常" . $e->getMessage());
return $this->array_callback(false, "请求异常" . $e->getMessage());
}
} else {
return array_callback(false, "未找到可通知的监测人员!");
return $this->array_callback(false, "未找到可通知的监测人员!");
}
}
... ... @@ -264,7 +264,7 @@ class WxxcxPush extends Base
public function sendWorkorderMessage($id,$temp)
{
if (empty($id)) {
return array_callback(false, "id不能为空");
return $this->array_callback(false, "id不能为空");
}
$workorderInfo = Db::name("workorder_orders")->where("id", $id)->find();
... ... @@ -315,24 +315,24 @@ class WxxcxPush extends Base
// 执行提交操作
Db::commit();
return array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]);
return $this->array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]);
} catch (PDOException $e) {
Db::rollback();
return array_callback(false, "请求异常" . $e->getMessage());
return $this->array_callback(false, "请求异常" . $e->getMessage());
}
} else {
return array_callback(false, "未找到可通知的成员!");
return $this->array_callback(false, "未找到可通知的成员!");
}
} else {
return array_callback(false, "未找到推送人员");
return $this->array_callback(false, "未找到推送人员");
}
} else {
return array_callback(false, "未查找到有效的工单数据");
return $this->array_callback(false, "未查找到有效的工单数据");
}
... ... @@ -402,16 +402,16 @@ class WxxcxPush extends Base
if (!empty($res_arr) && $res_arr['errcode'] == "0") {
} else {
//推送失败,记录问题
return array_callback(true, "推1送成功".json_encode($res_arr));
return $this->array_callback(true, "推1送成功".json_encode($res_arr));
$insert_message_log_data['error_tips'] = json_encode($res_arr, JSON_UNESCAPED_UNICODE);
}
// 执行提交操作
Db::commit();
return array_callback(true, "推送成功");
return $this->array_callback(true, "推送成功");
} catch (PDOException $e) {
Db::rollback();
return array_callback(false, "请求异常" . $e->getMessage());
return $this->array_callback(false, "请求异常" . $e->getMessage());
}
... ... @@ -442,26 +442,228 @@ class WxxcxPush extends Base
'value5' => $reservation['remarks'],
);
$res = beingPushed(6, $openid, $page, $insert_message_log_data);
$res = $this->beingPushed(6, $openid, $page, $insert_message_log_data);
file_put_contents("kevin_wx_xcx_push.log", date("Y-m-d H:i:s") . "《" . $reservation_id . "》" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
$res_arr = !empty($res) ? json_decode($res, true) : [];
if (!empty($res_arr) && $res_arr['errcode'] == "0") {
} else {
//推送失败,记录问题
return array_callback(true, "推1送成功".json_encode($res_arr));
return $this->$this->array_callback(true, "推1送成功".json_encode($res_arr));
$insert_message_log_data['error_tips'] = json_encode($res_arr, JSON_UNESCAPED_UNICODE);
}
// 执行提交操作
Db::commit();
return array_callback(true, "推送成功");
return $this->$this->array_callback(true, "推送成功");
} catch (PDOException $e) {
Db::rollback();
return array_callback(false, "请求异常" . $e->getMessage());
return $this->$this->array_callback(false, "请求异常" . $e->getMessage());
}
}
}
/**
* 小程序模板推送选择类型
* @param $type @模板类型
* @param $openid @接收人ID
* @param $page @跳转页面
* @param $temp @具体提醒参数
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
function beingPushed($type, $openid, $page, $temp)
{
$data = [];
$data['touser'] = $openid;
$data['page'] = $page;
//模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
switch ($type) {
case 1:
//待审批事项提醒(新版本的长期订阅)
$data['template_id'] = "ws6bz6-WyHHA-upU2oRzc_C5toDUexe9ZicQ-ITtImA";
$data['data'] = [
"thing10" => [
'value' =>$temp['value1'],//审核状态(待处理)
],
"thing12" => [
'value' => $temp['value2'],//申请人(测试黄超)
],
"thing8" => [
'value' => $temp['value3'],//原因(入州报备审核)
]
];
break;
case 2:
//审核结果通知(新版本的长期订阅)
$data['template_id'] = "Qt2xqfH8uQyTm1A0ReNxeybtAydAhfhi4HinnyB5f0s";
$data['data'] = [
"thing1" => [
'value' => $temp['value1'],//提醒内容(已审核)
],
// "name1" => [
// 'value' => $temp['value2'],//审核人
// ],
"thing4" => [
'value' => $temp['value3'],//提示说明
]
];
break;
case 3:
//待审批事项提醒(老版本的一次性订阅)
$data['template_id'] = "vVOonN76AFjxgz77iG-hcWrH6HJ-vPGKyIyAK0VzPIk";
$data['data'] = [
"thing1" => [
'value' => $temp['value1'],//待办事项
],
"thing4" => [
'value' => $temp['value2'],//流程状态
],
"thing2" => [
'value' => $temp['value3'],//申请人
],
"time3" => [
'value' => $temp['value4'],//申请时间
],
"thing5" => [
'value' => $temp['value5'],//备注描述
]
];
break;
case 4:
//审核结果通知(老版本的一次性订阅)
$data['template_id'] = "qR9reAuv_Ulelyg1H2xbN-GoWGWFRhS0t4nhtvnFr5Q";
$data['data'] = [
"character_string1" => [
'value' => $temp['value1'],//审核结果
],
"date3" => [
'value' => $temp['value2'],//审核人
],
"thing5" => [
'value' => $temp['value3'],//审批时间
],
"thing6" => [
'value' => $temp['value4'],//审批时间
],
"thing7" => [
'value' => $temp['value5'],//审批时间
]
];
break;
case 5:
//预约结果通知
$data['template_id'] = "oczyQ_SabASMQRRhDedXRGUEzCAuGh1xBw8sp2HVPvQ";
$data['data'] = [
"thing1" => [
'value' => $temp['value1'],//备注
],
"thing2" => [
'value' =>$temp['value2'],//日期
],
"number3" => [
'value' => $temp['value3'],//就诊人
],
"time4" => [
'value' => $temp['value4'],//就诊人
],
"thing6" => [
'value' => $temp['value5'],//就诊人
]
];
break;
case 6:
//预约结果通知
$data['template_id'] = "Dfvkyn3So2YE5aVJtkUTFWdjgzpo6VvWkNHZBOMb_n4";
$data['data'] = [
"character_string1" => [
'value' => $temp['value1'],//备注
],
"number2" => [
'value' =>$temp['value2'],//日期
],
"name3" => [
'value' => $temp['value3'],//就诊人
],
"date4" => [
'value' => $temp['value4'],//就诊人
],
"thing9" => [
'value' => $temp['value5'],//就诊人
]
];
break;
}
return $this->sendSubscribeMessage($data);
}
/**
* 小程序订阅消息推送
* @param $data
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
function sendSubscribeMessage($data)
{
//access_token
$access_token =$this->getAccessToken();
//请求url
$url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=' . $access_token;
//file_put_contents('notify.txt',$data.PHP_EOL,FILE_APPEND);
//跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
$data['miniprogram_state'] = 'formal';
return $this->curlPost($url, json_encode($data));
}
/**
* 获取access_token
* @return mixed
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
function getAccessToken()
{
$wx_xcx_token = \think\Db::name("wechat_token")->where("type", "wx_xcx")->find();
if (empty($wx_xcx_token) || empty($wx_xcx_token['access_token']) || $wx_xcx_token['over_time'] <= time()) {
//微信小程序失效
//当前时间戳
$now_time = strtotime(date('Y-m-d H:i:s', time()));
//获取新的access_token
$appid = config("site.wxxcx_AppID");
$secret = config("site.wxxcx_AppSecret");
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret;
$res = json_decode(file_get_contents($url), true);
$access_token = $res['access_token'];
if (!empty($access_token)) {
$time = time();
$update_data = [
"access_token" => $access_token,
"over_time" => $time + 7200,
"type" => "wx_xcx",
"updatetime" => $time
];
if (!empty($wx_xcx_token)) {
//更新
\think\Db::name("wechat_token")->where("id", $wx_xcx_token['id'])->update($update_data);
} else {
//新增
\think\Db::name("wechat_token")->insertGetId($update_data);
}
}
} else {
$access_token = $wx_xcx_token['access_token'];
}
return $access_token;
}
function array_callback($state = true, $msg = '', $data = array())
{
return array('state' => $state, 'msg' => $msg, 'data' => $data);
}
}
... ...
... ... @@ -44,3 +44,5 @@
2024-05-17 17:50:11《187》"{\"errcode\":0,\"errmsg\":\"ok\",\"msgid\":3461930549634482182}"
2024-05-24 12:19:49《188》"{\"errcode\":0,\"errmsg\":\"ok\",\"msgid\":3471744849597251586}"
2024-06-05 17:35:07《196》"{\"errcode\":40003,\"errmsg\":\"invalid openid rid: 6660314b-736be89e-400147ed\"}"
2024-06-06 11:50:39《224》"{\"errcode\":0,\"errmsg\":\"ok\",\"msgid\":3490559665207672840}"
2024-06-06 11:51:16《224》"{\"errcode\":0,\"errmsg\":\"ok\",\"msgid\":3490560289051672577}"
... ...