npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wxjssdkconfig

v0.0.5

Published

weixin js sdk signature

Downloads

7

Readme

weixinJsSdkConfig

微信js sdk服务端签名生成接口(微信JS-SDK说明文档)

使用方法

	/* 初始化 */
	var WxJSConfig = require("wxjssdkconfig");
	var wxJsConfig = new WxJSConfig("AppId","AppSecrect");
	
	/* 传入url,获取签名数据 */
	/* callback 回调函数参数:
				error:若无错误,error为null,否则为错误对象
				data:签名数据,json格式
	*/
	wxJsConfig.getJSSConfig(url,callback);
	
	

注意

  • 必须在全局环境下实例 WxJSConfig类 ,引用认证获取的token和ticket字段需要缓存在应用中(两小时),若每次请求签名都重新实例化WxJSConfig会导致缓存不可用。

代码示例(express)

    //服务端
	var WxJSConfig = require("wxjssdkconfig");
	//该实例化不要放在下面的路由函数中,需要保证每次都是同一个对象调用getJSSConfig方法
	var wxJsConfig = new WxJSConfig("AppId","AppSecrect");
	var router = express.Router();
	
	router.get('/api/wxJsToken',function(req, res){
        var url = decodeURIComponent(req.query.url);

        wxJsConfig.getJSSConfig(url,function(error,configData){
            var result = {
                errNo:0,
                errObj:null,
                data:null
            }
            if (error) {
                result.errNo = 1;
                result.errObj = error;
            }
            else {
                result.data = configData;
            }
            res.end(JSON.stringify(result));
        });
    });

    //浏览器端
    if (window.wx) {
        $.ajax({
            url:"/api/wxJsToken",
            data:{
                //必须传入当前页面的url数据,获取签名
                url:encodeURIComponent(location.href)
            },
            dataType: 'json',
            success: function(data){
                if (data.errNo == 0) {
                    var configData = data.data;
                    configData.jsApiList = ["previewImage"];

                    wx.config(configData);
                    wx.ready(function(){
                        //认证成功,开始使用API
                    });
                    wx.error(function(){
                        //认证失败,可能是未在公共帐号中添加域名支持,可能是jsApiList中存在没有权限的js API
                    });
                }
                else {

                }
            },
            error: function(xhr, type){
                console.log("get weixin js config failed");
            }
        })
    };

    也可以由服务端将签名数据直接输入在页面,前端就不需要使用ajax获取.