1. 程式人生 > >微信開發技術總結

微信開發技術總結

1、獲取OPENID的方法

步驟:【1】獲取code【2】獲取openid

仔細閱讀微信介面文件,可以發現,獲取opendi需要兩個介面

https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect
https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
if(!!auth_code){//如果存在code
//請求第二個介面,根據code獲取openid
}else{//如果不存在code
//請求第一個介面,獲取code,並跳轉回當前頁面
}

2、伺服器端SESSION快取ACCESS_TOKEN的方法

//設定過期時間
session_set_cookie_params($lifeTime); 
session_start();
//判斷快取是否存在
if(如果不存在){
	//獲取值
	//快取值
}else{
	//從快取獲取值
}

3、遇到的問題

(1)對if(!!!a)的理解

(2)var a;和var a=0;的理解

(3)ajax請求下面獲取資料的一個坑

(4)從meta標籤裡面獲取值

(5)設定cookie的一個外掛https://github.com/carhartl/jquery-cookie