公眾號第三方平台開發 教程一 創建公眾號第三方平台
公眾號第三方平台開發 教程二 component_verify_ticket和accessToken的獲取
公眾號第三方平台開發 教程三 微信公眾號授權第三方平台
公眾號第三方平台開發 教程四 代公眾號發起網頁授權說明
公眾號第三方平台開發 教程五 代公眾號處理消息和事件
公眾號第三方平台開發 教程六 代公眾號使用JS SDK說明
另,感謝一下這個大蝦的博客,這幾篇東西都是在他的博文基礎上完成的,他的博客里也有一些接口代碼可以下載
微信開發系列教程
這一部分挺簡單的,其實就是在頁面上放一個鏈接,引導用戶跳轉即可
鏈接的格式如下:
這里對參數做一下說明
component_appid即第三方平台的APPID(如下圖)
pre_auth_code為預授權碼,用獲得的第三方平台AccessToken作為參數進行獲取,具體看下面的代碼
redirect_uri為用戶同意授權之后跳轉的鏈接,同時會向該頁面發送用戶的授權碼auth_code,通過這個授權碼即可請求到公眾號的授權信息
獲取預授權碼的函數
/// <summary> /// 用於獲取預授權碼。預授權碼用於公眾號授權時的第三方平台方安全驗證 /// </summary> /// <param name="component_verify_ticket"></param> /// <returns></returns> public static ResponseCreatePreauthCode Create_preauthcode(string component_access_token) { var urlFormat = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token={0}"; object data = null; data = new { component_appid = Config.ServerAppID, }; return CommonJsonSend.Send<ResponseCreatePreauthCode>(component_access_token, urlFormat, data, timeOut: Config.TIME_OUT); }
返回結果示例
{
"pre_auth_code":"Cx_Dk6qiBE0Dmx4EmlT3oRfArPvwSQ-oa3NL_fwHM7VI08r52wazoZX2Rhpz1dEw",
"expires_in":600
}
獲得用戶授權碼之后,用auth_Code作為參數請求公眾號信息。
component_access_token為第三方平台accessToken
/// <summary> /// 使用授權碼換取公眾號的授權信息 /// </summary> /// <param name="component_access_token"></param> /// <returns></returns> public static PublicWechatAuthorizerInfo Query_auth(string component_access_token, string auth_code_value) { var urlFormat = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token={0}"; object data = null; data = new { component_appid = Config.ServerAppID, authorization_code = auth_code_value }; return CommonJsonSend.Send<PublicWechatAuthorizerInfo>(component_access_token, urlFormat, data, timeOut: Config.TIME_OUT); }
返回結果示例
{
"authorization_info": {
"authorizer_appid": "wxf8b4f85f3a794e77",
"authorizer_access_token": "QXjUqNqfYVH0yBE1iI_7vuN_9gQbpjfK7hYwJ3P7xOa88a89-Aga5x1NMYJyB8G2yKt1KCl0nPC3W9GJzw0Zzq_dBxc8pxIGUNi_bFes0qM",
"expires_in": 7200,
"authorizer_refresh_token": "dTo-YCXPL4llX-u1W1pPpnp8Hgm4wpJtlR6iV0doKdY",
"func_info": [
{
"funcscope_category": {
"id": 1
}
},
{
"funcscope_category": {
"id": 2
}
},
{
"funcscope_category": {
"id": 3
}
}
]
}