wugg 2 years ago
parent
commit
e711695cd4
3 changed files with 40 additions and 11 deletions
  1. 28 0
      app/admin/common/YouZan.php
  2. 10 10
      app/youzan/controller/Push.php
  3. 2 1
      composer.json

+ 28 - 0
app/admin/common/YouZan.php

@@ -0,0 +1,28 @@
+<?php
+
+
+namespace app\admin\common;
+use Youzan\Open\Client;
+use Youzan\Open\Token;
+
+class YouZan
+{
+    public $Client;
+    public $Token;
+    public  $clientId='deaaebe6484c129787';
+    public  $clientSecret='3c654aa2fbc1b5da788ffdba45fb96f0';
+    public function __construct()
+    {
+        $this->Token =new Token($this->clientId,$this->clientSecret);
+        $this->Client=new Client($this->GetToken());
+    }
+
+    public function GetData($method,$apiVersion,$params){
+        return $this->Client->post($method, $apiVersion, $params);
+    }
+    public function GetToken(){
+       return  $this->Token->getSelfAppToken("silent",["refresh"=>true]);
+    }
+
+
+}

+ 10 - 10
app/youzan/controller/Push.php

@@ -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));
-   }
+    }
 }

+ 2 - 1
composer.json

@@ -25,7 +25,8 @@
         "topthink/think-orm": "^2.0",
         "topthink/think-multi-app": "^1.0",
         "phpoffice/phpexcel": "^1.8",
-        "huaweicloud/huaweicloud-sdk-php": "3.0.3-beta"
+        "huaweicloud/huaweicloud-sdk-php": "3.0.3-beta",
+        "youzanyun/open-sdk": "^2.0"
     },
     "require-dev": {
         "symfony/var-dumper": "^4.2",