mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-25 10:56:38 +08:00
Update Push.php
This commit is contained in:
parent
ca2fdaa2f2
commit
5f202eec5c
@ -29,13 +29,13 @@ class Push extends Controller
|
|||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信APPID
|
* 公众号 APPID
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $appid;
|
protected $appid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信用户OPENID
|
* 微信用户 OPENID
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $openid;
|
protected $openid;
|
||||||
@ -48,7 +48,7 @@ class Push extends Controller
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信OPENID
|
* 请求微信 OPENID
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $fromOpenid;
|
protected $fromOpenid;
|
||||||
@ -94,23 +94,23 @@ class Push extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (WechatService::instance()->getType() === 'thr') {
|
if (WechatService::instance()->getType() === 'thr') {
|
||||||
$this->forceJson = true; // 强制回复 JSON 到 SERVICE
|
$this->forceJson = true; // 直接回复JSON数据到SERVICE
|
||||||
$this->forceCustom = false; // 强制使用客服消息模式推送
|
$this->forceCustom = false; // 直接使用客服消息模式推送
|
||||||
$this->appid = $this->request->post('appid', '', null);
|
$this->appid = $this->request->post('appid', '', null);
|
||||||
$this->openid = $this->request->post('openid', '', null);
|
$this->openid = $this->request->post('openid', '', null);
|
||||||
$this->encrypt = boolval($this->request->post('encrypt', 0));
|
$this->encrypt = boolval($this->request->post('encrypt', 0));
|
||||||
$this->receive = $this->_objectToLowerKey(json_decode(input('params', '[]'), true));
|
$this->receive = $this->_arrayChangeKeyCase(json_decode(input('params', '[]'), true));
|
||||||
if (empty($this->appid) || empty($this->openid) || empty($this->receive)) {
|
if (empty($this->appid) || empty($this->openid) || empty($this->receive)) {
|
||||||
throw new \think\Exception('微信API实例缺失必要参数[appid,openid,receive]');
|
throw new \think\Exception('微信API实例缺失必要参数[appid,openid,receive]');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->forceJson = false; // 暂停返回JSON消息对象
|
$this->forceJson = false; // 直接返回JSON对象数据
|
||||||
$this->forceCustom = false; // 暂停使用客户消息模式
|
$this->forceCustom = false; // 直接使用客服消息回复
|
||||||
$this->appid = WechatService::instance()->getAppid();
|
$this->appid = WechatService::instance()->getAppid();
|
||||||
$this->wechat = WechatService::WeChatReceive();
|
$this->wechat = WechatService::WeChatReceive();
|
||||||
$this->openid = $this->wechat->getOpenid();
|
$this->openid = $this->wechat->getOpenid();
|
||||||
$this->encrypt = $this->wechat->isEncrypt();
|
$this->encrypt = $this->wechat->isEncrypt();
|
||||||
$this->receive = $this->_objectToLowerKey($this->wechat->getReceive());
|
$this->receive = $this->_arrayChangeKeyCase($this->wechat->getReceive());
|
||||||
}
|
}
|
||||||
$this->fromOpenid = $this->receive['tousername'];
|
$this->fromOpenid = $this->receive['tousername'];
|
||||||
// 消息类型:text, event, image, voice, shortvideo, location, link
|
// 消息类型:text, event, image, voice, shortvideo, location, link
|
||||||
@ -323,11 +323,11 @@ class Push extends Controller
|
|||||||
* @param array $data
|
* @param array $data
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function _objectToLowerKey(array $data)
|
private function _arrayChangeKeyCase(array $data)
|
||||||
{
|
{
|
||||||
$data = array_change_key_case($data, CASE_LOWER);
|
$data = array_change_key_case($data, CASE_LOWER);
|
||||||
foreach ($data as $key => $vo) if (is_array($vo)) {
|
foreach ($data as $key => $vo) if (is_array($vo)) {
|
||||||
$data[$key] = $this->_objectToLowerKey($vo);
|
$data[$key] = $this->_arrayChangeKeyCase($vo);
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user