* @version : HuoMp 1.0 */ namespace mini\sdk\controller; use huo\controller\game\Game; use huolib\tool\StrUtils; use think\Controller; use think\Log; class PaybackController extends Controller { private $param = []; function _initialize() { parent::_initialize(); $this->param = $this->request->param(); /* 记录请求数据 */ Log::write( $this->request->server('HTTP_HOST').$this->request->server('REQUEST_URI').'?'.$this->request->getContent(), Log::LOG ); } /** * 支付回调测试 * http://doc.1tsdk.com/138?page_id=3353 * 【域名】/cp/payback/test */ public function notify() { die('SUCCESS'); $_param = $this->param; /* 1 查询是否具有访问权限 */ $this->checkAuth(); $this->checkParam(); $_data['app_id'] = $_param['app_id']; $_data['cp_order_id'] = $_param['cp_order_id']; $_data['mem_id'] = $_param['mem_id']; $_data['order_id'] = $_param['order_id']; $_data['order_status'] = $_param['order_status']; $_data['pay_time'] = $_param['pay_time']; $_data['product_id'] = $_param['product_id']; $_data['product_name'] = $_param['product_name']; $_data['product_price'] = $_param['product_price']; $_data['ext'] = $_param['ext']; $_sign = $_param['sign']; $_data = StrUtils::argSort($_data); $_check_str = http_build_query($_data); $_app_key = $this->getAppKey($_data['app_id']); if (empty($_app_key)) { die('FAILURE'); } $_check_sign = md5($_check_str.'&app_key='.$_app_key); if ($_sign != $_check_sign) { die('FAILURE'); } die('SUCCESS'); } private function checkParam() { $_param = $this->param; if (!isset($_param['app_id']) || empty($_param['app_id'])) { die('app_id 参数为空'); } if (!isset($_param['cp_order_id']) || empty($_param['cp_order_id'])) { die('cp_order_id 参数为空'); } if (!isset($_param['mem_id']) || empty($_param['mem_id'])) { die('mem_id 参数为空'); } else { // $_mg_mem_id = HuoSession::getMgMemId(); // if ($_mg_mem_id != $_param['mem_id']) { // die('mem_id 错误 玩家不存在'); // } } if (!isset($_param['order_id']) || empty($_param['order_id'])) { die('order_id 参数为空'); } if (!isset($_param['order_status']) || empty($_param['order_status'])) { die('order_status 参数为空'); } if (!isset($_param['pay_time']) || empty($_param['pay_time'])) { die('pay_time 参数为空'); } if (!isset($_param['product_id']) || empty($_param['product_id'])) { die('product_id 参数为空'); } if (!isset($_param['product_name']) || empty($_param['product_name'])) { die('product_name 参数为空'); } if (!isset($_param['product_price']) || empty($_param['product_price'])) { die('product_price 参数为空'); } if (!isset($_param['ext'])) { die('ext 参数为空'); } if (!isset($_param['sign']) || empty($_param['sign'])) { die('sign 参数为空'); } } /** * 获取APPKEY * * @param $app_id * * @return bool */ private function getAppKey($app_id) { $_app_key = (new Game())->getAppKey($app_id); if (empty($_app_key)) { return false; } return $_app_key; } /** * 校验权限 * * @return bool */ private function checkAuth() { $_ip = $this->request->ip(); if (!is_string($_ip)) { die('FAILURE'); } return true; } }