外观
订阅消息简化配置流程
配置
在Usersubnum Model文件里面配置相关信息
php
const SUBNUM_LIST = array(
[
'title' => '语音通话提醒', //标题
'memo' => '*通话提醒通知模板,关键词(对方姓名,通话类型,来电时间,备注)<br>
*模板编号:34868,如果匹配不到该模板编号,请自定义参数名', //备注
'key' => 'voicecallremind', //字段key
'key_p' => 'voicecallremind_parameter', //开关key
'filed' => array(
[
'val' => 'thing1', //模板字段
'key' => 'voicecallremind_name', //系统关联字段
'name' => '对方姓名', //字段名称
],
[
'val' => 'thing2',
'key' => 'voicecallremind_type',
'name' => '通话类型'
],
[
'val' => 'time3',
'key' => 'voicecallremind_time',
'name' => '来电时间'
],
[
'val' => 'thing4',
'key' => 'voicecallremind_memo',
'name' => '备注'
],
), //订阅消息字段
'plugin_key' => 'plugin_audiocall',
'subnum_key' => 'voicecallremind_num', //收集数量表字段
]
);调用函数
调用发放方法在Usersubnum Model文件里面sendSubnum
php
/**
* @param $key 关联配置key
* @param $user_id 用户id
* @param $page 页面地址
* @param $data 字段数据 字段数据 索引key为配置数据字段值 filed.key
*/
public function sendSubnum($key, $user_id, $page, $data){
$user = User::find($user_id);
$openid = $user["openid"];
$info = self::getSubnumInfo($key);
if (empty($info)){
return ;
}
$system = System::get_curr();
$subnewstel = json_decode($system["subnewstel"], true);
$template_id = $subnewstel[$info['key']];
if ($subnewstel[$info['key_p']] == 1) {
$templatedata = [];
foreach ($info['filed'] as $item){
$templatedata[$subnewstel[$item['key']]] = [
"value" => $data[$item['key']]
];
}
} else {
foreach ($info['filed'] as $item){
$templatedata[$item['val']] = [
"value" => $data[$item['key']]//金额
];
}
}
sendSubnews2($openid, $template_id, $page, $templatedata);
(new Usersubnum())->setReduce($user['id'], $info['subnum_key']);
return true;
}示例
调用示例
php
$url = "pages/home/home";
(new Usersubnum())->sendSubnum('voicecallremind', $listener_user_id, $url, [
'voicecallremind_name' => $call_user["nickname"],
'voicecallremind_type' => $type == 0 ? '语音通话':'视频通话',
'voicecallremind_time' => date('Y-m-d H:i:s'),
'voicecallremind_memo' => '请马上点击进入接听',
]);