zoukankan      html  css  js  c++  java
  • 微信小程序

    https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code
    
    调用改接口获取
    openid
    session_key
    unionid(unionid需要满足某些条件才能获取到,使用unionid的话仅使用该接口是不行的)
    
    所以一般登录需要小程序调用调用
    wx.login 获取JSCODE
    
    wx.getUserInfo 获取encryptedData
    encryptedData是加密后的用户信息,
    包含openid,unionid,nickName,avatarUrl等信息
    encryptedData配合session_key解密获取用户信息

    java版解密算法(从网上找的,也看不大懂,主要增加了一些判断,使用基本不会出现异常了)

    public class DecryptUtil {
    
        // 算法名称
        final String KEY_ALGORITHM = "AES";
    
        // 加解密算法/模式/填充方式
        final String algorithmStr = "AES/CBC/PKCS7Padding";
        //
        private Key key;
        private Cipher cipher;
    
        public void init(byte[] keyBytes) {
    
            // 如果密钥不足16位,那么就补足. 这个if 中的内容很重要
            int base = 16;
            if (keyBytes.length % base != 0) {
                int groups = keyBytes.length / base + (keyBytes.length % base != 0 ? 1 : 0);
                byte[] temp = new byte[groups * base];
                Arrays.fill(temp, (byte) 0);
                System.arraycopy(keyBytes, 0, temp, 0, keyBytes.length);
                keyBytes = temp;
            }
            // 初始化
            Security.addProvider(new BouncyCastleProvider());
            // 转化成JAVA的密钥格式
            key = new SecretKeySpec(keyBytes, KEY_ALGORITHM);
            try {
                // 初始化cipher
                cipher = Cipher.getInstance(algorithmStr);
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            } catch (NoSuchPaddingException e) {
                e.printStackTrace();
            }
        }
    
        public NutMap decryptToMap(String encryptedDataStr, String keyBytesStr, String ivStr){
            if(Strings.isBlank(encryptedDataStr)){
                return null;
            }
            if(Strings.isBlank(keyBytesStr)){
                return null;
            }
            if(Strings.isBlank(ivStr)){
                return null;
            }
            byte[] buffer = decrypt(encryptedDataStr,keyBytesStr,ivStr);
            if(buffer == null || buffer.length == 0){
                return null;
            }
            String result = null;
            try {
                result = new String(buffer,"UTF-8");
            } catch (UnsupportedEncodingException e) {
    
            }
            if(result == null || result.length() == 0){
                return null;
            }
            return NutMap.WRAP(result);
        }
    
        /**
         * 解密方法
         * @return
         */
        public byte[] decrypt(String encryptedDataStr, String keyBytesStr, String ivStr) {
            byte[] encryptedText = null;
            byte[] encryptedData = null;
            byte[] sessionKey = null;
            byte[] iv = null;
    
            try {
                sessionKey = Base64.decodeBase64(keyBytesStr);
                encryptedData = Base64.decodeBase64(encryptedDataStr);
                iv = Base64.decodeBase64(ivStr);
    
                init(sessionKey);
    
                cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));
                encryptedText = cipher.doFinal(encryptedData);
            } catch (Exception e) {
                //e.printStackTrace();
    
            }
            return encryptedText;
        }
    
    }

    引入 weui.wxss 样式

    下载地址

    直接在app.wxss里面引用dist/style/widget下的组件的wxss

  • 相关阅读:
    【jQuery 分页】jQuery分页功能的实现
    【jQuery 使用】 利用jQuery.prop("outerHTML")获取包含自身在内的HTML元素的HTML代码
    Openfire 是怎么存离线消息
    openfire过滤脏话插件,控制消息是否发送
    openfire升级指南
    openfire教程网
    redis web 客户端工具 redis-admin
    敏捷开发Nutz
    openfire消息通知推送
    一步步教你实现跨游览器的颜色选择器
  • 原文地址:https://www.cnblogs.com/rchao/p/9608084.html
Copyright © 2011-2022 走看看