You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.3 KiB
PHTML
96 lines
2.3 KiB
PHTML
2 years ago
|
<?php
|
||
|
namespace Sdk\Controller;
|
||
|
|
||
|
use Think\Controller\RestController;
|
||
|
|
||
|
class CommonController extends RestController {
|
||
|
protected function _initialize() {
|
||
|
//加载配置
|
||
|
C(api('Config/lists'));
|
||
|
|
||
|
//if(!preg_match("/apple_alipay_pay/",GetCurUrl())&&!preg_match("/apple_weixin_pay/",GetCurUrl())){
|
||
|
|
||
|
$data = json_decode(base64_decode($_POST['key']),true);
|
||
|
file_put_contents(dirname(__FILE__) . '/data.txt',json_encode($data));
|
||
|
if(empty($data) || empty($data['game_id'])){
|
||
|
echo base64_encode(json_encode(array("status"=>0,"return_msg"=>"操作数据或游戏ID不能为空")));exit();
|
||
|
}
|
||
|
$md5Sign = $data['md5_sign'];
|
||
|
unset($data['md5_sign']);
|
||
|
|
||
|
#获取游戏key
|
||
|
$game_data = M("game","tab_")->alias("g")->field("s.*")
|
||
|
->where(['g.apply_status'=>1,'g.id'=>$data['game_id']])
|
||
|
->join("left join tab_game_set s on s.game_id = g.id")
|
||
|
->find();
|
||
|
if(empty($game_data)){
|
||
|
$this->set_message(0,"fail","游戏不存在或未通过审核");
|
||
|
}
|
||
|
|
||
|
$md5_sign = $this->encrypt_md5($data,$game_data["access_key"]);//mengchuang DZQkkiz!@#9527
|
||
|
if($md5Sign !== $md5_sign){
|
||
|
$this->set_message(0,"fail","验签失败");
|
||
|
}
|
||
|
|
||
|
define(PID,$data['promote_id']);
|
||
|
define(UID,$data['user_id']);
|
||
|
|
||
|
|
||
|
//}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
public function set_message($status=0,$return_code="fail",$return_msg="操作失败"){
|
||
|
$msg = array(
|
||
|
"status" => $status,
|
||
|
"return_code" => $return_code,
|
||
|
"return_msg" => $return_msg
|
||
|
);
|
||
|
echo base64_encode(json_encode($msg));
|
||
|
exit();
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
*验证签名
|
||
|
*/
|
||
|
public function validation_sign($encrypt="",$md5_sign=""){
|
||
|
$signString = $this->arrSort($encrypt);
|
||
|
$md5Str = $this->encrypt_md5($signString,$key="");
|
||
|
if($md5Str === $md5_sign){
|
||
|
return true;
|
||
|
}
|
||
|
else{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
*对数据进行排序
|
||
|
*/
|
||
|
private function arrSort($para){
|
||
|
ksort($para);
|
||
|
reset($para);
|
||
|
return $para;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
*MD5验签加密
|
||
|
*/
|
||
|
public function encrypt_md5($param="",$key=""){
|
||
|
#对数组进行排序拼接
|
||
|
if(is_array($param)){
|
||
|
$md5Str = implode($this->arrSort($param));
|
||
|
}
|
||
|
else{
|
||
|
$md5Str = $param;
|
||
|
}
|
||
|
$md5 = md5($md5Str . $key);
|
||
|
return '' === $param ? 'false' : $md5;
|
||
|
}
|
||
|
|
||
|
}
|