微信企業番号取得OpenIDプロセス
1804 ワード
define('CorpID', "wx82e2c31215d9a5a7");
define('CorpSecret', ""); // -> -> -> -> ( )->Secret
define('AgentID', "20"); // ID
require_once("../../class/wxqiye.class.php");
$weixin = new class_wxqiye();
// var_dump($weixin);
if (isset($_COOKIE["openid"]) && !empty($_COOKIE["openid"])){
$openid = $_COOKIE["openid"];
}else{
if (!isset($_GET["code"])){
$redirect_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$jumpurl = $weixin->oauth2_authorize($redirect_url, "snsapi_base", "123");
// var_dump($jumpurl);
Header("Location: $jumpurl");
}else{
$userinfo = $weixin->oauth2_get_userinfo($_GET["code"]);
var_dump($userinfo);
// array(2) { ["UserId"]=> string(6) "taojin" ["DeviceId"]=> string(32) "be434bab16db86bd40995edf1194ef3b" }
// array(2) { ["DeviceId"]=> string(32) "e0a66223f897a826717fc134930afe85" ["OpenId"]=> string(28) "o_UE0s2L8mVlEAhlScmE0dfjJojg" }
if (isset($userinfo["OpenId"])){
$openid = $userinfo["OpenId"];
}else{
$openinfo = $weixin->convert_openid($userinfo["UserId"]);
var_dump($openinfo);
// array(4) { ["errcode"]=> int(0) ["errmsg"]=> string(2) "ok" ["openid"]=> string(28) "oxzslwktZytLTM7zwlU3QODJNzQ0" ["appid"]=> string(18) "wxcc23554f93463d7c" }
$openid = $openinfo["openid"];
}
setcookie("openid", $openid, time()+86400); //
}
}
転載先:https://www.cnblogs.com/txw1958/p/11188928.html