|
@@ -11,41 +11,41 @@ use think\Request;
|
|
|
class Push extends BaseController
|
|
|
{
|
|
|
public $data=[];
|
|
|
- public $clientId='';
|
|
|
- public $clientSecret='';
|
|
|
+ public $clientId='deaaebe6484c129787';
|
|
|
+ public $clientSecret='3c654aa2fbc1b5da788ffdba45fb96f0';
|
|
|
public $httpSign='';
|
|
|
public $httpType='';
|
|
|
public $httpClientId='';
|
|
|
public function __construct(App $app)
|
|
|
{
|
|
|
parent::__construct($app);
|
|
|
- $this->data=$this->request->post();
|
|
|
+ $this->data=file_get_contents("php://input");
|
|
|
$header =$this->request->header();
|
|
|
$this->httpClientId=$header['client-id'];
|
|
|
- $this->httpType=$header['event-sign'];
|
|
|
- $this->httpSign=$header['event-type'];
|
|
|
+ $this->httpType=$header['event-type'];
|
|
|
+ $this->httpSign=$header['event-sign'];
|
|
|
|
|
|
}
|
|
|
|
|
|
public function GetPush(){
|
|
|
- if($this->sign != $this->httpSign) {
|
|
|
+ if($this->sign() != $this->httpSign) {
|
|
|
// sign校验失败, 自行检查
|
|
|
return json_encode(array("code" => 0, "msg" => "faild"));
|
|
|
}
|
|
|
+ $httpData = json_decode($this->data, true);
|
|
|
// 业务逻辑处理
|
|
|
// 根据 Type 来识别消息事件类型, 具体的 type 值以文档为准, 此处仅是示例
|
|
|
if($this->httpType == "POINTS") {
|
|
|
// 建议异步处理业务逻辑
|
|
|
// http request body
|
|
|
- $httpData = json_decode($this->data, true);
|
|
|
// msg内容经过 urlencode 编码,需进行解码
|
|
|
$msg = json_decode(urldecode($httpData['msg']), true);
|
|
|
//todo
|
|
|
}
|
|
|
// 响应结果
|
|
|
return json_encode(array("code" => 0, "msg" => "success"));
|
|
|
- }
|
|
|
- public function sign(){
|
|
|
+ }
|
|
|
+ public function sign(){
|
|
|
return md5(sprintf('%s%s%s', $this->clientId, $this->data, $this->clientSecret));
|
|
|
- }
|
|
|
+ }
|
|
|
}
|