微信JS-SDK说明文档---自己总结了config时的参数获取方式

http://203.195.235.76/jssdk/


1、引入js


http://res.wx.qq.com/open/js/jweixin-1.0.0.js



 https://res.wx.qq.com/open/js/jweixin-1.0.0.js

 2、初始化

 wx.config({
    debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
    appId: '', // 必填,公众号的唯一标识
    timestamp: , // 必填,生成签名的时间戳 见2.4
    nonceStr: '', // 必填,生成签名的随机串 见2.4
    signature: '',// 必填,签名,见 2.3
    jsApiList: [] // 必填,需要使用的JS接口列表,所有JS接口列表见 2.5
});


2.1、获取  access token

https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET


APPSECRET获取方式 ,登录公众号,基本配置
AppID(应用ID) wxd44e9d16ce2bdb2d
AppSecret 需要输入正确的密码才可以看见
 


返回{"access_token":"ACCESS_TOKEN","expires_in":7200}

2.2、获取jsapi_ticket

https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi
返回
{
"errcode":0,
"errmsg":"ok",
"ticket":"bxLdikRXVbTPdHSM05e5u5sUoXNKd8-41ZO3MhKoyN5OfkWITDGgnr2fwJ0m9E8NYzWKVZvdVtaUgWvsdshFKA",
"expires_in":7200
}

2.3、签名算法
    2.3.1 noncestr字符串常量
    
        
        jsapi_ticket=sM4AOVdWfPE4DxkXGEs8VMCPGGVi4C3VM0P37wVUCFvkVAy_90u5h9nbSlYy3-Sl-HhTdfl2fzFy1AOcHKP7qg
        &
        noncestr=Wm3WZYTPz0wzccnW
        &
        timestamp=1414587457
        &
        url=http://mp.weixin.qq.com?params=value   (签名用的url必须是调用JS接口页面的完整URL)

    2.3.2、对上面数据进行shal1加密得到signature:

        0f9de62fce790f9a083d5c99e95740ceb90c27ed

2.4、加签算法类

import java.util.UUID;
import java.util.Map;
import java.util.HashMap;
import java.util.Formatter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.io.UnsupportedEncodingException;  

class Sign {
    public static void main(String[] args) {
        String jsapi_ticket = "jsapi_ticket";

        // 注意 URL 一定要动态获取,不能 hardcode
        String url = "http://example.com";
        Map<String, String> ret = sign(jsapi_ticket, url);
        for (Map.Entry entry : ret.entrySet()) {
            System.out.println(entry.getKey() + ", " + entry.getValue());
        }
    };

    public static Map<String, String> sign(String jsapi_ticket, String url) {
        Map<String, String> ret = new HashMap<String, String>();
        String nonce_str = create_nonce_str();
        String timestamp = create_timestamp();
        String string1;
        String signature = "";

        //注意这里参数名必须全部小写,且必须有序
        string1 = "jsapi_ticket=" + jsapi_ticket +
                  "&noncestr=" + nonce_str +
                  "&timestamp=" + timestamp +
                  "&url=" + url;
        System.out.println(string1);

        try
        {
            MessageDigest crypt = MessageDigest.getInstance("SHA-1");
            crypt.reset();
            crypt.update(string1.getBytes("UTF-8"));
            signature = byteToHex(crypt.digest());
        }
        catch (NoSuchAlgorithmException e)
        {
            e.printStackTrace();
        }
        catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        }

        ret.put("url", url);
        ret.put("jsapi_ticket", jsapi_ticket);
        ret.put("nonceStr", nonce_str);
        ret.put("timestamp", timestamp);
        ret.put("signature", signature);

        return ret;
    }

    private static String byteToHex(final byte[] hash) {
        Formatter formatter = new Formatter();
        for (byte b : hash)
        {
            formatter.format("%02x", b);
        }
        String result = formatter.toString();
        formatter.close();
        return result;
    }

    private static String create_nonce_str() {
        return UUID.randomUUID().toString();
    }

    private static String create_timestamp() {
        return Long.toString(System.currentTimeMillis() / 1000);
    }
}


2.5、jsApiList的值


     onMenuShareTimeline
    onMenuShareAppMessage
    onMenuShareQQ
    onMenuShareWeibo
    onMenuShareQZone
    startRecord
    stopRecord
    onVoiceRecordEnd
    playVoice
    pauseVoice
    stopVoice
    onVoicePlayEnd
    uploadVoice
    downloadVoice
    chooseImage
    previewImage
    uploadImage
    downloadImage
    translateVoice
    getNetworkType
    openLocation
    getLocation
    hideOptionMenu
    showOptionMenu
    hideMenuItems
    showMenuItems
    hideAllNonBaseMenuItem
    showAllNonBaseMenuItem
    closeWindow
    scanQRCode
    chooseWXPay
    openProductSpecificView
    addCard
    chooseCard
    openCard

基本类

    举报: "menuItem:exposeArticle"
    调整字体: "menuItem:setFont"
    日间模式: "menuItem:dayMode"
    夜间模式: "menuItem:nightMode"
    刷新: "menuItem:refresh"
    查看公众号(已添加): "menuItem:profile"
    查看公众号(未添加): "menuItem:addContact"

传播类
    这块知识把时间绑定到了分享按钮,目前没有办法直接去操作按钮。
    发送给朋友: "menuItem:share:appMessage"
    分享到朋友圈: "menuItem:share:timeline"
    分享到QQ: "menuItem:share:qq"
    分享到Weibo: "menuItem:share:weiboApp"
    收藏: "menuItem:favorite"
    分享到FB: "menuItem:share:facebook"
    分享到 QQ 空间/menuItem:share:QZone

保护类

    编辑标签: "menuItem:editTag"
    删除: "menuItem:delete"
    复制链接: "menuItem:copyUrl"
    原网页: "menuItem:originPage"
    阅读模式: "menuItem:readMode"
    在QQ浏览器中打开: "menuItem:openWithQQBrowser"
    在Safari中打开: "menuItem:openWithSafari"
    邮件: "menuItem:share:email"
    一些特殊公众号: "menuItem:share:brand"



<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
<script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
  <script type="text/javascript">
  <!--
     wx.config({
    debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
    appId: 'wx99a066ed3be3d52e', // 必填,公众号的唯一标识
    timestamp: 1462521975, // 必填,生成签名的时间戳
    nonceStr: '9f2c415b-0b8a-48be-ae2c-b4b92a76f494', // 必填,生成签名的随机串
    signature: '0f978b1b7884092cfb825fed7ea18bc9b9fd3b27',// 必填,签名,见附录1
    jsApiList: ['onMenuShareAppMessage'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});

wx.ready(function () {
 
  wx.onMenuShareTimeline({

        title: '分享标题', // 分享标题

        link:"分享的url,以http或https开头",

        imgUrl: "http://images2015.cnblogs.com/blog/340216/201603/340216-20160330130105738-634805951.png" // 分享图标

    });

    // 获取“分享给朋友”按钮点击状态及自定义分享内容接口

    wx.onMenuShareAppMessage({

        title: '分享标题', // 分享标题

        desc: "分享描述", // 分享描述

        link:"分享的url,以http或https开头",

        imgUrl: "http://images2015.cnblogs.com/blog/340216/201603/340216-20160330130105738-634805951.png", // 分享图标

        type: 'link', // 分享类型,music、video或link,不填默认为link

    });
 
});

     
  //-->
  </script>
 </head>
 <body>
 
 </body>
</html>
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值