2 Star 0 Fork 0

易企秀/hd-lottery-demo-php

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.php 3.18 KB
一键复制 编辑 原始数据 按行查看 历史
chenlongxing 提交于 2022-03-17 18:39 . init project
<?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;
}
?>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/eqxiu-ee/hd-lottery-demo-php.git
git@gitee.com:eqxiu-ee/hd-lottery-demo-php.git
eqxiu-ee
hd-lottery-demo-php
hd-lottery-demo-php
master

搜索帮助