看网上说的要引用类库,然后我现在用的是tp5.1的
tp5.1取消了Loader::import方法以及import和vendor助手函数
然后一直搞不成,
最后看了那个类库,直接使用,
public function getWechatUserPhone()
{
$appid = "自己的小程序appid";
$id = $this->request->post();
$sessionKey = $id['session_key'];
$encryptedData = $id['encryptedData'];
$iv = $id['iv'];
//小程序开发账户
if (strlen($sessionKey) != 24) {
return "1";
}
$aesKey = base64_decode($sessionKey);
if (strlen($iv) != 24) {
return "2";
}
$aesIV = base64_decode($iv);
$aesCipher = base64_decode($encryptedData);
$result = openssl_decrypt($aesCipher, "AES-128-CBC", $aesKey, 1, $aesIV);
$dataObj = json_decode($result);
if ($dataObj == null) {
return "3";
}
if ($dataObj->watermark->appid != $appid) {
return "4";
}
$data = $result;
return $data;
}
输出就能获取到用户的手机号了!!