在2017年的時(shí)候就做了這個(gè)分析,一直沒(méi)發(fā)出來(lái)。??注意文中使用的ide版本是Mac 版的,ide version: 1.01.1711020,不推薦在生產(chǎn)環(huán)境中使用。
準(zhǔn)備工作
下載IDE版本:1.01.1711020
美化開(kāi)發(fā)工具js代碼:在js目錄執(zhí)行命令
find . -type f -name '*.js' -exec js-beautify -r -s 2 -p -f '{}' \;打開(kāi)針對(duì)IDE的調(diào)試工具:在./app.nw/js/core/index.js 第81行 init() 過(guò)后 加入以下代碼:
nw.Window.get().showDevTools();在IDE源碼中使用
global.contentWindow.console.log來(lái)打印變量
微信開(kāi)發(fā)者工具登陸接口
URL配置文件
全局搜索 LOGIN_URL
登錄頁(yè)面的固定url:
https://open.weixin.qq.com/connect/qrconnect?appid=xxx&redirect_uri=https%3a%2f%2fmp.weixin.qq.com%2fdebug%2fcgi-bin%2fwebdebugger%2fqrcode&scope=snsapi_login&state=login
他返回二維碼掃碼頁(yè)面(html)。
此處代碼可以全局搜索 _longPollURL 定位到該文件。
在集成到發(fā)布系統(tǒng)的時(shí)候,完全可以用headless chrome 或者是 phantom js 模擬請(qǐng)求來(lái)一步搞定。
ide中登陸流程如下
// step1: 拿到二維碼鏈接
const content = ''; // 上面接口返回的html
const qrcodeReg = /src="\/(connect\/qrcode\/.+)"/;
const s = c.match(qrcodeReg)[1];
const src = `https://open.weixin.qq.com/${s}`; // 拼接出登陸二維碼url
// step2 : 拿到輪詢鏈接, 用于輪詢登陸狀態(tài)
const longPollReg = /"(https:\/\/long.open.weixin.qq.com\/connect\/l\/qrconnect\?uuid=.+?)"/;
const pollUrl = content.match(longPollReg)[1];
// step3 輪詢登陸結(jié)果
const LOGIN_WX_ERRR_CODE = {
SUCCESS: 405,
SCANNED: 404,
CANCELLED: 403,
TIMEOUT: 402,
ERROR: 500,
KEEP_ALIVE: 408
}
const platform = "darwin" === process.platform ? "darwin" : "win";
// poll
request({
url: `${pollUrl}&last=""}&_=${+new Date()}`,
headers: { "Content-Type": "application/javascript" },
timeout: 60000
}, (a, b, c) => {
// 返回了一段js代碼
eval(c);
const e = window.wx_errcode;
switch(e) {
case LOGIN_WX_ERRR_CODE.SUCCESS:
const loginRedirectUrl = `https://mp.weixin.qq.com/debug/cgi-bin/webdebugger/qrcode?code=${window.wx_code}&state=${platform}`;
// 拿到登陸信息
request({ url: loginRedirectUrl }, (a, b, res) => {
let a = JSON.parse(res);
let i = b.headers,
j = i["debugger-signature"],
k = i["debugger-newticket"],
l = +new Date(),
m = {
signature: j,
newticket: k,
openid: a.openid,
nickName: a.nickname,
headUrl:
a.headurl ||
"https://res.wx.qq.com/zh_CN/htmledition/v2/images/web_wechat_no_contect.png",
ticketExpiredTime: 1e3 * a.ticket_expired_time + l,
signatureExpiredTime: 1e3 * a.signature_expired_time + l,
sex: 1 === a.sex ? "male" : "female",
province: a.province,
city: a.city,
contry: a.contry
};
});
}
});
生成體驗(yàn)版二維碼
體驗(yàn)版二維碼鏈接: https://open.weixin.qq.com/sns/getexpappinfo?appid=xxx&path=pages%2Fhome.html#wechat-redirect
??????????????????????注意
預(yù)覽接口 和 上傳接口的 http method 都是 post,下面表格列的參數(shù) 是需要附加到url上面的query參數(shù)。
post的 body數(shù)據(jù)就是打包好的.wx文件,示例代碼 見(jiàn)文章 微信小程序上傳/預(yù)覽代碼分析 末尾。
預(yù)覽接口
| 接口描述 | 預(yù)覽小程序 |
|---|---|
| 域名 | https://servicewechat.com |
| 路徑 | /wxa-dev/testsource |
| 請(qǐng)求方法 | POST |
| 入?yún)?/td> | 參數(shù)見(jiàn)下面 |
| 返回 | 返回結(jié)果見(jiàn)下面 |
query參數(shù):
{
_r: '0.8530581592723374', // 隨機(jī)數(shù)
appid: 'xxx', // 小程序appid
platform: 0, // 平臺(tái)
ext_appid: '',
os: 'darwin',
clientversion: '101171018',
gzip: 1,
path: 'pages/home?',// 預(yù)覽頁(yè)面的路徑
newticket: 'jGUKNzQ59CI5yEoZRgmVP7P6PCnY1xaTv7QSdOXYoIM', // 未知,該數(shù)據(jù)從登陸接口拿到
os: 'darwin', // 系統(tǒng)
clientversion: '1.01.171018'
}
返回結(jié)果
{
"baseresponse": {
"errcode": 0,
"errmsg": "test source success."
},
"qrcode_img": " base64 圖片 ",
"wxpkg_size": 48269,
"compile_time": 0,
"widget_size": 0
}
上傳接口
| 接口描述 | 上傳小程序 |
|---|---|
| 域名 | https://servicewechat.com |
| 路徑 | /wxa-dev/commitsource |
| 請(qǐng)求方法 | POST |
| 入?yún)?/td> | 參數(shù)見(jiàn)下面 |
| 返回 | 返回結(jié)果見(jiàn)下面 |
query 入?yún)?/h4>
{
_r: '0.8530581592723374', // 隨機(jī)數(shù)
appid: 'xxx', // 小程序appid
platform: 0, // 平臺(tái)
ext_appid: '',
os: 'darwin',
clientversion: '101171018',
"user-version": 1,
"user-desc": "xxx",
"uuid": "",
gzip: 1,
newticket: 'jGUKNzQ59CI5yEoZRgmVP7P6PCnY1xaTv7QSdOXYoIM', // 未知,該數(shù)據(jù)從登陸接口拿到
os: 'darwin', // 系統(tǒng)
clientversion: '1.01.171018'
}
返回結(jié)果
{
"baseresponse": {
"errcode": 0,
"errmsg": "commit source success."
},
"wxpkg_size": 48269,
"compile_time": 0,
}
檢查是否已經(jīng)設(shè)置了預(yù)覽版
{
protocol: "https:",
host: "servicewechat.com",
pathname: "/wxa-dev-logic/getcommitqrcode",
query: {
_r: "0.014995344596100635",
os: "darwin",
clientversion: "1011711300",
appid: "xxx",
newticket: "uVMVEwpFifCRfXjx53x9ORZsbn1X_ygFWl61kwaEeBg"
}
}
{
_r: '0.8530581592723374', // 隨機(jī)數(shù)
appid: 'xxx', // 小程序appid
platform: 0, // 平臺(tái)
ext_appid: '',
os: 'darwin',
clientversion: '101171018',
"user-version": 1,
"user-desc": "xxx",
"uuid": "",
gzip: 1,
newticket: 'jGUKNzQ59CI5yEoZRgmVP7P6PCnY1xaTv7QSdOXYoIM', // 未知,該數(shù)據(jù)從登陸接口拿到
os: 'darwin', // 系統(tǒng)
clientversion: '1.01.171018'
}
{
"baseresponse": {
"errcode": 0,
"errmsg": "commit source success."
},
"wxpkg_size": 48269,
"compile_time": 0,
}
{
protocol: "https:",
host: "servicewechat.com",
pathname: "/wxa-dev-logic/getcommitqrcode",
query: {
_r: "0.014995344596100635",
os: "darwin",
clientversion: "1011711300",
appid: "xxx",
newticket: "uVMVEwpFifCRfXjx53x9ORZsbn1X_ygFWl61kwaEeBg"
}
}