代码拉取完成,页面将自动刷新
<?php
include_once "pkcs7Encoder.php";
$signatureKey = "eqxiu";
$encodingKey = "qwertyuiopasdfghjklzxcvbnmlkjhgfdsaqwertyui";
//index.php/lottery/mobile
$path = $_SERVER["PATH_INFO"];
if(isset($path)) {
$json = file_get_contents('php://input');
$data = json_decode($json);
if (strcmp($path , "/lottery/mobile") == 0) {
$ts = $data->timestamp;
$nonce = $data->nonce;
$signature = $data->signature;
$sha1Signature = sha1hex($signatureKey, $ts, $nonce);
if(strcmp($signature , $sha1Signature) != 0) {
echo "签名验证失败";
return;
}
$decryptJson = decrypt($data->msgEncrypt);
$mapJson = json_decode($decryptJson);
$id = $mapJson->id;
$mobile = $mapJson->mobile;
//TODO your logic code
$resMap = array('lottery'=>2, 'message'=>'没有中奖', 'url'=>'https://www.baidu.com');
header("content-type:application/json;charset=utf-8");
echo json_encode($resMap);
}else if(strcmp($path ,"/lottery/wechat") == 0) {
$ts = $data->timestamp;
$nonce = $data->nonce;
$signature = $data->signature;
$msgEncrypt = $data->msgEncrypt;
$sha1Signature = sha1hex($signatureKey, $ts, $nonce);
if(strcmp($signature , $sha1Signature) != 0) {
echo "签名验证失败";
return;
}
$decryptJson = decrypt($data->msgEncrypt);
$mapJson = json_decode($decryptJson);
$id = $mapJson->id;
$openId = $mapJson->openId;
$nickName = $mapJson->nickName;
$gender = $mapJson->gender;
$city = $mapJson->city;
$country = $mapJson->country;
//TODO your logic code
$resMap = array('lottery'=>2, 'message'=>'非会员不可参与抽奖,请先注册!', 'url'=>'https://www.baidu.com');
header("content-type:application/json;charset=utf-8");
echo json_encode($resMap);
}else if(strcmp($path, "/lottery/custom") ==0) {
$ts = $data->timestamp;
$nonce = $data->nonce;
$signature = $data->signature;
$msgEncrypt = $data->msgEncrypt;
$sha1Signature = sha1hex($signatureKey, $ts, $nonce);
if(strcmp($signature , $sha1Signature) != 0) {
echo "签名验证失败";
return;
}
$decryptJson = decrypt($data->msgEncrypt);
$mapJson = json_decode($decryptJson);
$id = $mapJson->id;
$openId = $mapJson->openId;
//TODO your logic code
$resMap = array('lottery'=>2, 'message'=>'非会员不可参与抽奖,请先注册!', 'url'=>'https://www.baidu.com');
header("content-type:application/json;charset=utf-8");
echo json_encode($resMap);
} else {
die("not found");
}
}else {
die("not found");
}
function sha1hex(...$args) {
try {
sort($args, SORT_STRING);
$t = implode($args);
$hashed = sha1($t);
return $hashed;
}catch(Exception $e) {
return ;
}
}
function decrypt($encrypted) {
global $encodingKey;
try {
//使用BASE64对需要解密的字符串进行解码
$aesKey = base64_decode($encodingKey);
$ciphertext_dec = base64_decode($encrypted);
$iv = substr($aesKey, 0, 16);
//解密
$decrypted = openssl_decrypt($ciphertext_dec, 'AES-256-CBC', $aesKey, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
} catch (Exception $e) {
echo $e;
}
try {
//去除补位字符
$pkc_encoder = new PKCS7Encoder;
$result = $pkc_encoder->decode($decrypted);
} catch (Exception $e) {
echo $e;
}
return $result;
}
?>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。