123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- declare (strict_types = 1);
- namespace app\youzan\controller;
- use app\BaseController;
- use think\App;
- use think\facade\Cache;
- use think\Request;
- class Push extends BaseController
- {
- public $data=[];
- public $clientId='deaaebe6484c129787';
- public $clientSecret='3c654aa2fbc1b5da788ffdba45fb96f0';
- public $httpSign='';
- public $httpType='';
- public $httpClientId='';
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->data=file_get_contents("php://input");
- $header =$this->request->header();
- $this->httpClientId=$header['client-id'];
- $this->httpType=$header['event-type'];
- $this->httpSign=$header['event-sign'];
- }
- public function GetPush(){
- 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
- // msg内容经过 urlencode 编码,需进行解码
- $msg = json_decode(urldecode($httpData['msg']), true);
- //todo
- }
- // 响应结果
- return json_encode(array("code" => 0, "msg" => "success"));
- }
- public function sign(){
- return md5(sprintf('%s%s%s', $this->clientId, $this->data, $this->clientSecret));
- }
- }
|