小程序代碼:
解密代碼:
<?
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換取網(wǎng)頁授權(quán)access_token
$jsondecode = json_decode($weixin); //對JSON格式的字符串進行編碼
$array = get_object_vars($jsondecode);//轉(zhuǎn)換成數(shù)組
//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");
}
?>