2 Star 2 Fork 0

OI 开源 / WeChat-offiaccount

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

WeChat-offiaccount

微信公众号辅助调试服务器 + 微信官方js-sdk,支持typescript开发

downloads Version GitHub repo stars

本项目用于搭建一个微信公众号本地测试环境,同时集成了微信官方js-sdk,支持typescript开发,为了简单,我们基于测试号来说明。

非测试号也可以使用,填入正确字段即可,如果有问题,可以issue给我们留言!

如何本地调试?

首先需要在./offiaccount.config.js中填入自己的appID和appsecret。

接入微信公众平台开发

为了接入你首先需要的是“接口配置信息”,这里需要填入./offiaccount.config.js中的token,和“测试号管理”页面的保持一致即可。

然后你把这个项目在外网可以访问的服务器上运行后,配置后即可通过验证,然后就可以依据接口文档实现业务逻辑。

JS-SDK使用

比如你启动后,手机可以通过http://192.168.0.6:20000(无需外网可以访问,如果电脑和手机连同一个wifi,像这里的例子,用局域网ip即可)访问,那么,“JS接口安全域名”中的域名配置成192.168.0.6:20000即可。

然后在微信中打开上面的html页面即可(到此为止,你就可以在你的html页面使用JS-SDK能力了)。

如何在项目中使用?

为了方便随时随地使用,我们发布了npm包,只需要项目中安装后就可以按照下面说明使用需要的能力了:

npm install --save wechat-offiaccount

JS-SDK使用

首先,准备一份配置文件,比如在当前目录下有一个文件offiaccount.config.js,内容如下:

// 具体的改为自己的即可
const config = {
    port:8080,
    appID: "",
    appsecret: ""
}
module.exports = config

然后,在package.json中配置启动命令:

{
    "scripts": {
        "offiaccount": "offiaccount-cli --config offiaccount.config.js"
    }
}

然后执行启动命令:

npm run offiaccount

接着,我们用浏览器最新的fetch举例子:

import wx from "wechat-offiaccount"
fetch("http://" + window.location.hostname + ":8080/JsApiSignature?url=" + window.location.href.split('#')[0], {
    method: "get"
}).then(function (response) {
    response.json()
        .then(function (res) {

            wx.config({
                debug: true,
                appId: res.appId, 
                timestamp: res.timestamp,
                nonceStr: res.nonceStr,
                signature: res.signature,
                jsApiList: ['chooseImage'] // 必填,需要使用的JS接口列表
            })

            wx.error(function (res) {
                console.error(res)
            })

        })
})

上面已经配置好了,并且申请了wx.chooseImage权限,后续用的时候,只需要:

import wx from "wechat-offiaccount"
wx.ready(function () {
    console.log('准备好了!')

    // todo
})

比如访问的地址是:http://192.168.0.6:20000/index.html

接入微信公众平台开发

把当前目录下的文件offiaccount.config.js内容修改如下:

// 具体的改为自己的即可
const config = {
    token: '',
    port: 8080,
    appID: "",
    appsecret: "",
    handler(req, res) {
        // 需要自己处理业务请求
    }
};
module.exports = config

然后需要启动后部署到外网可以访问的服务器上,最后就可以作为微信公众号后台服务器使用,然后进行各种测试学习了。

版权

MIT License

Copyright (c) zxl20070701 走一步,再走一步

MIT License Copyright (c) zxl20070701 走一步,再走一步 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

微信公众号辅助调试服务器 + 微信官方js-sdk,支持typescript开发 💯 展开 收起
JavaScript 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/oi-contrib/WeChat-offiaccount.git
git@gitee.com:oi-contrib/WeChat-offiaccount.git
oi-contrib
WeChat-offiaccount
WeChat-offiaccount
master

搜索帮助