Index.php
<?php
namespace app\youzan\controller;
use think\Controller;
class Index extends Controller {
protected $client_id;
protected $client_secret;
public function initialize() {
$this->client_id = config('youzan.client_id');
$this->client_secret = config('youzan.client_secret');
}
public function index() {
$json = file_get_contents('php://input');
$data = json_decode($json, true);
if ($data) {
$result = array("code" => 0, "msg" => "success");
//var_dump($result);
var_dump(json_encode($result));
}
/**
* 判断消息是否合法,若合法则返回成功标识
*/
$msg = $data['msg'];
$sign_string = $this->client_id . "" . $msg . "" . $this->client_secret;
$sign = md5($sign_string);
if ($sign != $data['sign']) {
exit();
}
/**
* msg内容经过 urlencode 编码,需进行解码
*/
$msg = json_decode(urldecode($msg), true);
dump($msg);die;
}
}
client_id、client_secret自行在config/youzan.php中配置