Skip to content

Commit

Permalink
消息推送
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanson committed Oct 9, 2018
1 parent e38213a commit fe60db1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ $youzan = $youzan->oauth->createAuthorization($token['token']);
$result = $youzan->request('youzan.shop.get');
```

### 消息推送

```
// 消息结构体
$data = $youzan->push->parse();
$response = $youzan->push->response();
// $response 为 `Symfony\Component\HttpFoundation\Response` 实例
// 对于需要直接输出响应的框架,或者原生 PHP 环境下
$response->send();
// 而 laravel 中直接返回即可:
return $response;
```

## Help

QQ 群: 570769430
Expand Down
19 changes: 14 additions & 5 deletions src/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class Push
{
Expand All @@ -24,19 +25,17 @@ public function __construct($clientId, $secret, Request $request)
}

/**
* @return array
* @return Response|array
* @throws YouzanException
*/
public function parse()
{
$data = $this->request->getContent();

$data = json_decode($data, true);

echo json_encode(['code' => 0, 'msg' => 'success']);

if ($data['test'] === true) {
return;
if ($this->checkTest($data)) {
return false;
}

$this->checkSign($data);
Expand All @@ -46,6 +45,11 @@ public function parse()
return $data;
}

public function checkTest($data)
{
return $data['test'] === true;
}

public function checkSign($data)
{
$sign = md5($this->clientId.$data['msg'].$this->secret);
Expand All @@ -55,4 +59,9 @@ public function checkSign($data)
}
}

public function response()
{
return Response::create(json_encode(['code' => 0, 'msg' => 'success']));
}

}

0 comments on commit fe60db1

Please sign in to comment.