Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 请问一下在微信子自定义菜单中的url链接

请问一下在微信子自定义菜单中的url链接

Jun 23, 2016 pm 01:17 PM

我基于原有的微信平台CMS做了一个功能,然后把功能的链接放到菜单中,通过点击菜单进入页面。但是一开始可以顺利进入,还点了几次异步上传照片,但是会显示error openid:{wechat_id}错误提示。可是后来就不行了,进不了页面,一点就是在一个空白页面显示error openid:{wechat_id},在windows的微信开发者工具又显示no token ,后来又不知道怎么老是跳成手机端首页。恳求高手帮帮忙。


回复讨论(解决方案)

这些错误提示时你们自己代码写的吧,你要把对应代码发出来

这些错误提示时你们自己代码写的吧,你要把对应代码发出来



<?phpclass WapAction extends BaseAction{	public $token;	public $wecha_id;	public $fakeopenid;	public $fans;	public $homeInfo;	public $bottomeMenus;	public $wxuser;	public $user;	public $group;	public $company;	public $shareScript;	public $sign;	private $_appid;	private $_secret;	private $_redirect_uri;	private $_auth;	public $owxuser;	protected function _initialize()	{		parent::_initialize();		$this->_appid = C("appid");		$this->_secret = C("secret");		$this->time = 0;		$this->token = $this->_get("token");		if (ALI_FUWU_GROUP && (date("Y") == 2015)) {			$fuwuuserlist = M("fuwuuser")->where(array("token" => $this->token))->select();			foreach ($fuwuuserlist as $fuwuvo ) {				$fuwuuserinfo = M("userinfo")->where(array("token" => $this->token, "wecha_id" => $fuwuvo["wecha_id"]))->find();				if ($fuwuuserinfo == "") {					if ($fuwuvo["gender"] == "M") {						$fuwuvo["gender"] = 1;					}					else if ($fuwuvo["gender"] == "F") {						$fuwuvo["gender"] = 2;					}					else {						$fuwuvo["gender"] = 0;					}					$add_userinfo_hb = array("token" => $this->token, "wecha_id" => $fuwuvo["wecha_id"], "issub" => 1, "portrait" => $fuwuvo["avatar"], "truename" => $fuwuvo["real_name"], "nickname" => $fuwuvo["real_name"], "wechaname" => $fuwuvo["real_name"], "sex" => $fuwuvo["gender"]);					$add_userinfo_hb = array_map("nulltoblank", $add_userinfo_hb);					$id_userinfo = M("userinfo")->add($add_userinfo_hb);				}				else {					if (($fuwuuserinfo["portrait"] == "") || ($fuwuuserinfo["wechaname"] == "")) {						if ($fuwuvo["gender"] == "M") {							$fuwuvo["gender"] = 1;						}						else if ($fuwuvo["gender"] == "F") {							$fuwuvo["gender"] = 2;						}						else {							$fuwuvo["gender"] = 0;						}						$save_userinfo_hb = array("token" => $this->token, "wecha_id" => $fuwuvo["wecha_id"], "issub" => 1, "portrait" => $fuwuvo["avatar"], "truename" => $fuwuvo["real_name"], "nickname" => $fuwuvo["real_name"], "wechaname" => $fuwuvo["real_name"], "sex" => $fuwuvo["gender"]);						$save_userinfo_hb = array_map("nulltoblank", $save_userinfo_hb);						$up_userinfo = M("userinfo")->where(array("token" => $this->token, "wecha_id" => $fuwuvo["wecha_id"]))->save($save_userinfo_hb);					}				}			}		}		if (strlen($this->token)) {			$_SESSION["wap_token"] = $this->token;		}		if (!$this->token) {			$this->token = $_SESSION["wap_token"];		}		if (!empty($_SESSION["wap_token"])) {			$this->token = $_SESSION["wap_token"];		}		if (!$this->token && !strpos(MODULE_NAME, "Drp") === false) {			$id = $this->_get("id");			if ($id) {				$did = M("Distributor_store")->where(array("id" => $id))->getField("did");				$this->token = M("Distributor")->where(array("id" => $did))->getField("token");			}		}		$this->assign("token", $this->token);		if (!$this->token) {			exit("no token");		}		if ($this->token && !preg_match("/^[0-9a-zA-Z]{3,42}$/", $this->token)) {			exit("error token");		}		$this->wxuser = S("wxuser_" . $this->token);		if (!$this->wxuser || 1) {			$this->wxuser = D("Wxuser")->where(array("token" => $this->token))->find();			S("wxuser_" . $this->token, $this->wxuser);		}		$this->owxuser = $this->wxuser;		$this->assign("wxuser", $this->wxuser);		$this->_checkVipTime($this->wxuser);		$fake = 0;		if (($this->wxuser["winxintype"] != 3) && $this->_appid && $this->_secret) {			if ($this->wxuser["oauth"] == 1) {				if (!$this->isAgent) {					$this->wxuser["appid"] = trim($this->_appid);					$this->wxuser["appsecret"] = trim($this->_secret);				}				else {					$this->wxuser["appid"] = $this->thisAgent["appid"];					$this->wxuser["appsecret"] = $this->thisAgent["appsecret"];				}			}			$fake = 1;		}		$toAuth = 0;		if ((C("server_topdomain") == "paiyi.net.cn") && (C("site_url") != "http://weixintest.paiyi.net.cn")) {			$toAuth = 1;		}		else {			$toAuth = $this->wxuser["oauth"];		}		if ((C("server_topdomain") == "pigcms.cn") && ($this->wxuser["winxintype"] != 3)) {			$this->wxuser["appid"] = $this->_appid;			$this->wxuser["appsecret"] = $this->_secret;			$this->wxuser["oauth"] = 0;			$this->wxuser["is_domain"] = 1;			$fake = 1;		}		$wexintype = $this->wxuser["winxintype"];		$session_openid_name = "token_openid_" . $this->token;		$session_fakeopenid_name = "token_fakeopenid_" . $this->token;		$session_reopenid_name = "token_reopenid_" . $this->token;		$session_oauthed_name = "token_oauthed_" . $this->token;		$getUserInfoModules = getUserInfoModule::index();		$getUserinfo = 0;		if (isset($_GET["rget"]) || intval($_GET["ali"])) {			$_SESSION["otherSource"] = 1;			$toAuth = 0;			$this->wxuser["oauthinfo"] = 0;		}		if (isset($_SESSION["otherSource"])) {			$toAuth = 0;		}		if ($this->wxuser["oauthinfo"] && !$_SESSION[$session_oauthed_name]) {			if ($_SESSION[$session_openid_name]) {				$fansInfo = M("Userinfo")->where(array("token" => $this->token, "wecha_id" => $_SESSION[$session_openid_name]))->find();				if ($toAuth) {					if (!$fansInfo || !$fansInfo["wechaname"] || !$fansInfo["portrait"]) {						unset($_SESSION[$session_openid_name]);						$getUserinfo = 1;					}				}			}			else {				if (isset($_SESSION[$session_reopenid_name]) && $_SESSION[$session_reopenid_name]) {					$fansInfo = M("Userinfo")->where(array("token" => $this->token, "wecha_id" => $_SESSION[$session_reopenid_name]))->find();					if (!$fansInfo || !$fansInfo["wechaname"] || !$fansInfo["portrait"]) {						unset($_SESSION[$session_openid_name]);						unset($_SESSION[$session_reopenid_name]);						$getUserinfo = 1;					}				}				else {					$getUserinfo = 1;				}			}		}		$this->isFuwu = 0;		$this->isWechat = 0;		$userAgent = strtolower($_SERVER["HTTP_USER_AGENT"]);		if (strpos($userAgent, "alipayclient")) {			$this->isFuwu = 1;		}		else if (strpos($userAgent, "micromessenger")) {			$this->isWechat = 1;		}		if (!M("Weixin_account")->where(array("type" => 1))->find()) {			M("Wxuser")->where("1")->save(array("type" => 0));		}		$this->cookieToSession();		if ($_GET["wecha_id"] && ($_GET["wecha_id"] != $_SESSION[$session_openid_name]) && (3 != $wexintype)) {			unset($_SESSION[$session_openid_name]);			unset($_SESSION[$session_oauthed_name]);			cookie("oauth2_" . $this->token, NULL);		}		if ($this->isFuwu) {			if ($_GET["wecha_id"] != "") {				$this->wecha_id = $_GET["wecha_id"];			}			else {				$this->wecha_id = session("wecha_id");			}			session("wecha_id", $this->wecha_id);			$thisfuwuuser = M("fuwuuser")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->find();			$isFuwuoauth = session("isFuwuoauth");		}		if ($this->isFuwu && ($isFuwuoauth != "yes")) {			$fw_wecha_id = FuwuOAuth::index($this->token);			if ($fw_wecha_id != "no") {				$this->wecha_id = $fw_wecha_id;				session("wecha_id", $this->wecha_id);				session("isFuwuoauth", "yes");			}			else if ($this->wecha_id == "") {				$this->error("服务窗没有获取粉丝信息权限<br/>请在服务窗开发者中确认开通");				exit();			}			$_SESSION[$session_openid_name] = $this->wecha_id;			$_SESSION[$session_oauthed_name] = 1;		}		$users = M("Users")->where(array("id" => $this->wxuser["uid"]))->find();		if (("payReturn" == ACTION_NAME) && (0 < $users["is_syn"])) {			$_SESSION[$session_openid_name] = $_GET["wecha_id"];		}
Copy after login

if (empty($_SESSION[$session_openid_name]) && (0 < $users["is_syn"])) {			$_SESSION["auth_callback_" . $this->token] = array("url" => getSelfUrl(array("wecha_id")), "token" => $this->token);			$url = $users["source_domain"] . A("Home/Auth")->getCallbackUrl($users["is_syn"], "auth") . "token=" . $this->token . "&source=pigcms";			header("Location:" . $url);			exit();		}		if (2 == $users["is_syn"]) {			$url = $users["source_domain"] . A("Home/Auth")->getCallbackUrl($users["is_syn"], "follow") . "wecha_id=" . $_SESSION[$session_openid_name];			$this->_auth = json_decode(HttpClient::getInstance()->get($url));			if (1 == $this->_auth->code) {				M("Userinfo")->where(array("token" => $this->token, "wecha_id" => $_SESSION[$session_openid_name]))->setField("issub", 1);			}			else {				M("Home")->where(array("token" => $this->token))->setField("gzhurl", $this->_auth->follow->url);				$this->wxuser["qr"] = $this->_auth->follow->qrcode;				$this->wxuser["wxname"] = $this->_auth->follow->wechat;			}		}		if (!isset($_SESSION[$session_openid_name]) || !$_SESSION[$session_openid_name]) {			if ($this->isFuwu) {			}			else {				$apiOauth = new apiOauth();				if ((!$_GET["wecha_id"] || (urldecode($_GET["wecha_id"]) == "{wechat_id}")) && ($_GET["wecha_id"] != "no") && $this->wxuser["appid"] && ((($this->wxuser["type"] == 0) && ($this->wxuser["appsecret"] != "")) || ($this->wxuser["type"] == 1)) && ($toAuth == 1)) {					$token_info = $apiOauth->webOauth($this->wxuser, "", $fansInfo);				}				if (!empty($token_info)) {					$this->wecha_id = $token_info["openid"];					if (3 == $wexintype) {						$fake = 0;					}					if ($fake) {						if (isset($_SESSION[$session_fakeopenid_name])) {							$datainfo["issub"] = 1;							$this->wecha_id = $_SESSION[$session_fakeopenid_name];							$userinfoModel = M("Userinfo");							$userinfoData = $userinfoModel->where(array("token" => $this->token, "wecha_id" => $_SESSION[$session_fakeopenid_name]))->find();							if ($userinfoData) {								$fakeUserinfoData = $userinfoModel->where(array("token" => $this->token, "wecha_id" => $token_info["openid"], "fakeopenid" => $token_info["openid"]))->find();								if ($fakeUserinfoData) {									if ($userinfoModel->where(array("id" => $fakeUserinfoData["id"]))->save($this->_mergeUserinfo($userinfoData, $fakeUserinfoData))) {										$userinfoModel->where(array("id" => $userinfoData["id"]))->delete();									}								}								else {									$userinfoModel->where(array("id" => $userinfoData["id"]))->setField("fakeopenid", $token_info["openid"]);								}							}							else {								$fakeUserinfoData = $userinfoModel->where(array("token" => $this->token, "wecha_id" => $token_info["openid"], "fakeopenid" => $token_info["openid"]))->find();								if ($fakeUserinfoData) {									$userinfoModel->where(array("id" => $fakeUserinfoData["id"]))->setField("wecha_id", $_SESSION[$session_fakeopenid_name]);								}							}							$this->wecha_id = $_SESSION[$session_fakeopenid_name];						}						else {							$fansInfo = M("Userinfo")->where(array("token" => $this->token, "fakeopenid" => $token_info["openid"]))->find();							if ($fansInfo) {								$this->wecha_id = $fansInfo["wecha_id"];							}						}					}					if ($this->wxuser["oauthinfo"] && (MODULE_NAME != "Index")) {						$jsonui = $apiOauth->get_fans_info($token_info["access_token"], $token_info["openid"]);						if (isset($jsonui["openid"]) && $jsonui["openid"]) {							if ($fansInfo) {								$exist = $fansInfo["id"];								$issub = $fansInfo["issub"];							}							else {								$existInfo = M("Userinfo")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->find();								$issub = $existInfo["issub"];								$exist = $existInfo["id"];							}							$datainfo["wechaname"] = str_replace(array("'", "\\"), array(""), $jsonui["nickname"]);							$datainfo["sex"] = $jsonui["sex"];							$datainfo["portrait"] = $jsonui["headimgurl"];							$datainfo["token"] = $this->token;							$datainfo["wecha_id"] = $jsonui["openid"];							$datainfo["city"] = $jsonui["city"];							$datainfo["province"] = $jsonui["province"];							$datainfo["truename"] = $datainfo["wechaname"];							$datainfo["wecha_id"] = $this->wecha_id;							if ($fake) {								$datainfo["fakeopenid"] = $jsonui["openid"];							}							if (3 == $wexintype) {								$datainfo["fakeopenid"] = "";								$datainfo["issub"] = $this->_issubService($datainfo["wecha_id"]);							}							if ($exist) {								D("Userinfo")->where(array("id" => $exist))->save($datainfo);							}							else {								D("Userinfo")->add($datainfo);							}						}						else {							$this->error("授权不对哦,请重置您的appsecret!<br>" . $this->wxuser["appid"] . "<br>" . $this->wxuser["appsecret"] . "<br>" . $jsonui["errcode"], "#");							exit();						}					}					if (empty($this->wxuser["oauthinfo"]) && (MODULE_NAME != "Index")) {						if ($fansInfo) {							$exist = $fansInfo["id"];						}						else {							$existInfo = M("Userinfo")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->find();							$exist = $existInfo["id"];						}						$datainfo["token"] = $this->token;						$datainfo["wecha_id"] = $this->wecha_id;						if ($fake) {							$datainfo["fakeopenid"] = $token_info["openid"];						}						if (3 == $wexintype) {							$datainfo["fakeopenid"] = "";							$datainfo["issub"] = $this->_issubService($datainfo["wecha_id"]);						}						if ($exist) {							D("Userinfo")->where(array("id" => $exist))->save($datainfo);						}						else {							D("Userinfo")->add($datainfo);						}					}					$_SESSION[$session_openid_name] = $this->wecha_id;					$_SESSION[$session_oauthed_name] = 1;					cookie("oauth2_" . $this->token, array("wap_token" => $this->token, "wecha_id" => $this->wecha_id, "appid" => $this->wxuser["appid"]), 311040000);				}				else {					$this->wecha_id = $this->_get("wecha_id");					if ($fake && $toAuth && !isset($_GET["isappinstalled"])) {						$_SESSION[$session_fakeopenid_name] = $this->wecha_id;					}					if (!$toAuth) {						$_SESSION[$session_openid_name] = $this->wecha_id;					}					if (isset($_GET["wecha_id"]) && strlen($_GET["wecha_id"]) && $toAuth) {						$get_parms = $_GET;						unset($get_parms["wecha_id"]);						$get_parm_str = "";						if ($get_parms) {							$comma = "";							foreach ($get_parms as $gpk => $gpv ) {								$get_parm_str .= $comma . $gpk . "=" . $gpv;								$comma = "&";							}						}						$get_parm_str .= "&g=" . GROUP_NAME . "&m=" . MODULE_NAME . "&a=" . ACTION_NAME;						$_SESSION[$session_reopenid_name] = $this->wecha_id;						header("Location:" . $this->siteUrl . "/index.php?" . $get_parm_str);						exit();					}				}			}		}		else {			$this->wecha_id = $_SESSION[$session_openid_name];		}		if ($_GET["yundabao"] == 1) {			cookie("yundabao", "1", 31536000);		}		$yundabao = cookie("yundabao");		if ($yundabao != "1") {			if ($this->wecha_id && !preg_match("/^[0-9a-zA-Z_\-\s]{3,82}$/", $this->wecha_id)) {				exit("error openid:" . $this->wecha_id);			}		}
Copy after login



它就是有时输出  error openid:"  这一行的东西,有时又输出 no token ,然后不知道怎么有时又跳回首页,
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

See all articles