58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?php
|
|
use phprs\util\Verify;
|
|
use phprs\util\exceptions\Forbidden;
|
|
use phprs\util\Logger;
|
|
use phprs\util\exceptions\NotFound;
|
|
use phprs\ezsql\Sql;
|
|
use phprs\util\exceptions\BadRequest;
|
|
|
|
require_once 'apiBase.php';
|
|
|
|
/**
|
|
*
|
|
* 基类
|
|
* @path("/templateMessageBase")
|
|
*/
|
|
class templateMessageBase extends apiBase{
|
|
protected $weixin_appid; // 微信APPID
|
|
protected $weixin_secret_appid; // 微信secret_appid
|
|
/** @var WeiXinAccount */
|
|
protected $weixinHandler; // 微信接口操作对象
|
|
|
|
public function __construct() {
|
|
}
|
|
|
|
public function init_weixin($weixin_appid,$weixin_secret_appid) {
|
|
$account = array();
|
|
$account["key"] = $weixin_appid;
|
|
$account["secret"] = $weixin_secret_appid;
|
|
$this->weixinHandler = new WeiXinAccount($account);
|
|
}
|
|
|
|
/**
|
|
* 发送自定义的模板消息
|
|
* @param string $touser 发送给谁(微信openId)
|
|
* @param string $template_id 模板的id(通过微信后台或接口, 增加的模板产生的唯一id)
|
|
* @param array $data 消息体数据
|
|
* @param string $url 跳转地址
|
|
* @param string $topcolor 颜色
|
|
* @return array|bool true if the method call succeeded, false otherwise.
|
|
*/
|
|
public function do_send($touser, $template_id, $data, $url='',$topcolor = '#7B68EE') {
|
|
$pdo = $this->db;
|
|
return $this->weixinHandler->sendTplNotice($this->db,$pdo,$touser,$template_id,$data,$url,$topcolor);
|
|
}
|
|
|
|
public function SendMessage($to_user, $template_id, $target_url, $parameter, $color = '#7b68ee') {
|
|
$pdo = $this->db;
|
|
return $this->weixinHandler->SendTemplateMessage($to_user, $template_id, $target_url, $parameter, $color, $this->db, $pdo);
|
|
}
|
|
|
|
/** @inject("ioc_factory") */
|
|
private $factory;
|
|
/**
|
|
* @property({"default":"@db"})
|
|
* @var PDO
|
|
*/
|
|
public $db;
|
|
} |