104 lines
4.0 KiB
PHP
104 lines
4.0 KiB
PHP
<?php
|
|
/**
|
|
* Notes:私域通
|
|
* Created on: 2020/11/30 17:00
|
|
* Created by: dengbw
|
|
*/
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
require_once(COMMPATH . "/third_party/WeChat/WechatServer.php");
|
|
|
|
class Syt extends CI_Controller
|
|
{
|
|
private $log_file = 'plan_syt.log';
|
|
private $options;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this-> options = [
|
|
'token' => '',
|
|
'appid' => 'wxe66f905683582780',
|
|
'appsecret' => '9546cd4de877be13ce203f3e6140633f',
|
|
'encodingaeskey' => '',
|
|
'debug' => false
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Notes:发送一次性订阅
|
|
* Created on: 2020/11/30 17:02
|
|
* Created by: dengbw
|
|
* https://hd-api-dev.xiaoyu.com/plan/syt/subscribemsg
|
|
* https://api.test.haodian.cn/plan/syt/subscribemsg
|
|
* https://api.haodian.cn/plan/syt/subscribemsg
|
|
*/
|
|
public function subscribemsg()
|
|
{
|
|
$this->load->model('market/market_sylive_subscribemsg_model','mdSytSubscribemsg');
|
|
$date = date('Y-m-d H:i:s', strtotime('+2 minute'));//提前2分钟发送
|
|
$where['s_time<='] = $date;
|
|
$where['status'] = 0;
|
|
$res = $this->mdSytSubscribemsg->select($where, 'id asc', 1, 200);
|
|
$log = array();
|
|
if ($res) {
|
|
$this->load->model('market/market_sylive_activity_model','mdSytActivity');
|
|
$wechatS = new WechatServer($this->options);
|
|
$wechatS->checkAuth();
|
|
foreach ($res as $key => $value) {
|
|
$re_a = $this->mdSytActivity->get(array("activityId" => $value['a_id'], "status" => 0));
|
|
if ($re_a) {
|
|
$content = '您预约“' . $re_a['title'] . '”直播已经开始啦!赶紧进入直播间观看直播领取福利吧~';
|
|
$temp_arr = array(
|
|
'touser' => $value['openid'],
|
|
'template_id' => $value['template_id'],
|
|
'url' => $value['url'],
|
|
'scene' => $value['scene'],
|
|
'title' => '开播提醒',
|
|
'data' => array(
|
|
'content' => array('value' => $content)
|
|
)
|
|
);
|
|
$re = $wechatS->subscribeTemplateMessage($temp_arr);
|
|
if ($re) {//errcode 0(发送成功) 43101(已发送过)
|
|
$this->mdSytSubscribemsg->update(['status' => 1], ['id' => $value['id']]);
|
|
if ($re['errcode'] == 0) {
|
|
$log[] = $value['a_id'] . '=' . $value['openid'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
echo '<br>数据库获取:';
|
|
echo json_encode($res, JSON_UNESCAPED_UNICODE);
|
|
echo '<br><br>成功发送:';
|
|
$log && print_r($log);
|
|
$total = count($res);
|
|
$do = count($log);
|
|
debug_log("[info] " . __FUNCTION__ . "# date:{$date}; total:{$total}; do:{$do};", $this->log_file);
|
|
}
|
|
|
|
public function test(){
|
|
require_once(COMMPATH . "/third_party/WeChat/WechatServer.php");
|
|
$options = [
|
|
'token' => '',
|
|
'appid' => 'wxe66f905683582780',
|
|
'appsecret' => '9546cd4de877be13ce203f3e6140633f',
|
|
'encodingaeskey' => '',
|
|
'debug' => false
|
|
];
|
|
$wechatS = new WechatServer($options);
|
|
$token = $wechatS->checkAuth();
|
|
$content = '您预约直播已经开始啦!赶紧进入直播间观看直播领取福利吧~';
|
|
$temp_arr = array(
|
|
'touser' => 'ospBg6AXMlXNdgv_rzbFvBXAD4TU',
|
|
'template_id' => '4eHuGYK69_GTjOlzkp8HK8iJNFuKboTpO7Igc1CC_fQ',
|
|
'url' => 'https://liche-dev.xiaoyu.com/h5/market/sylive/act?skey=aWQ9MQ',
|
|
'scene' => 0,
|
|
'title' => '开播提醒',
|
|
'data' => array(
|
|
'content' => array('value' => $content)
|
|
)
|
|
);
|
|
$re = $wechatS->subscribeTemplateMessage($temp_arr);
|
|
}
|
|
|
|
} |