小程序代码:
解密代码:
<?
include_once "wxBizDataCrypt.php";
$appid = 'wxbf560de5780b2ab3';
$code = $_GET['code'];//获取code
$UserInfo = $_GET['UserInfo'];//获取code
$encryptedData=$_REQUEST["encryptedData"];
$iv=$_REQUEST["iv"];
$weixin = file_get_contents("https://api.weixin.qq.com/sns/jscode2session?appid=wxbf560de5780b2ab3&secret=fdd06def5f800bab2df2a3e73f140a1f&js_code=".$code."&grant_type=authorization_code");//通过code换取网页授权access_token
$jsondecode = json_decode($weixin); //对JSON格式的字符串进行编码
$array = get_object_vars($jsondecode);//转换成数组
//echo $array["session_key"];
$pc = new WXBizDataCrypt($appid, $array["session_key"]);
$errCode = $pc->decryptData($encryptedData, $iv, $data );
if ($errCode == 0) {
$dhok = json_decode($data,true);
$ncok = json_decode($UserInfo,true);
//print("电话:".$dhok['phoneNumber'] . "昵称:".$ncok['nickName']."头像:".$ncok['avatarUrl']."性别:".$ncok['gender']);
$dh=iconv("utf-8",'gb2312',$dhok['phoneNumber']);
$nc=iconv("utf-8",'gb2312',$ncok['nickName']);
$tx=iconv("utf-8",'gb2312',$ncok['avatarUrl']);
$xb=iconv("utf-8",'gb2312',$ncok['gender']);
$connstr="DRIVER=Microsoft Access Driver (*.mdb);
DBQ=".realpath("guanli/shuju/woai#asp#shuju.mdb");
$connid=odbc_connect($connstr,"","",SQL_CUR_USE_ODBC );
if (odbc_fetch_row(odbc_exec($connid,"select * from zxfk where dh='".$dh."'")))
{echo "0,2";
odbc_close($connid);
}
else
{
odbc_exec($connid,"insert into zxfk (nc,dh,xb,tx) values('$nc','$dh','$xb','$tx')");
odbc_close($connid);
echo "1,2";
}
} else {
print($errCode . "2");
}
?>