xctc-utils 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.ts +10 -2
- package/dist/crypto/index.d.ts +2 -2
- package/dist/weixin/index.js +14 -9
- package/package.json +1 -1
    
        package/app.ts
    CHANGED
    
    | @@ -5,10 +5,18 @@ | |
| 5 5 | 
             
            // ts-node app.ts
         | 
| 6 6 | 
             
            import {formatTimeStamp,formatStrTime} from "./src/time"
         | 
| 7 7 | 
             
            import {weixinUrlCode} from "./src/weixin"
         | 
| 8 | 
            -
            import {decrypt} from "./src/crypto"
         | 
| 8 | 
            +
            import {decrypt,encrypt} from "./src/crypto"
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            const congif = {
         | 
| 11 | 
            +
                path:"/setting/setting-config/setting-config-index",
         | 
| 12 | 
            +
                id:12,
         | 
| 13 | 
            +
                type:"shop"
         | 
| 14 | 
            +
            }
         | 
| 15 | 
            +
            // let word = encrypt( congif  ,"5uMz4R8r0926DkC8","5uMz4R8r0926DkC8")
         | 
| 16 | 
            +
            // console.log(word)
         | 
| 9 17 |  | 
| 10 18 | 
             
            let word = "8CF99EE640F8175269E6B83795902CAD2DCA8039E5FED78C9F16CA17501F37DB95F7B899A88A99075FB8D84C64AE65DCAC82FF4B039D6D7ACCF952F63A3BB7267CDDAC4202D4986DD5DB69D67DEDE440"
         | 
| 11 | 
            -
            let val = decrypt(word | 
| 19 | 
            +
            let val = decrypt( word )
         | 
| 12 20 | 
             
            console.log("val",val)
         | 
| 13 21 | 
             
            function app(){
         | 
| 14 22 | 
             
                console.log("xxxx")
         | 
    
        package/dist/crypto/index.d.ts
    CHANGED
    
    | @@ -1,2 +1,2 @@ | |
| 1 | 
            -
            export declare function encrypt(word: any, key | 
| 2 | 
            -
            export declare function decrypt(word: any, key | 
| 1 | 
            +
            export declare function encrypt(word: any, key?: any, iv?: any): string;
         | 
| 2 | 
            +
            export declare function decrypt(word: any, key?: any, iv?: any): any;
         | 
    
        package/dist/weixin/index.js
    CHANGED
    
    | @@ -7,9 +7,12 @@ var utils_1 = require("../utils"); | |
| 7 7 | 
             
            var crypto_1 = require("../crypto");
         | 
| 8 8 | 
             
            var w = window;
         | 
| 9 9 | 
             
            var loc = w.location;
         | 
| 10 | 
            +
            var defaultKey = "5uMz4R8rop26DkC8";
         | 
| 11 | 
            +
            var defaultIv = "5uMz4Rsd0926DkC8";
         | 
| 10 12 | 
             
            var weixinConfig = {};
         | 
| 11 13 | 
             
            function weixinUrlCode(config) {
         | 
| 12 | 
            -
                weixinConfig = config;
         | 
| 14 | 
            +
                weixinConfig = config || {};
         | 
| 15 | 
            +
                var cryptoiv = weixinConfig.cryptoiv, cryptokey = weixinConfig.cryptokey;
         | 
| 13 16 | 
             
                var search = loc.search; // ?code=0916SzFa1KH9TA0Ke7Ha1AQx6446SzFr&state=123
         | 
| 14 17 | 
             
                // 获取地址栏返回 code 参数
         | 
| 15 18 | 
             
                var codeKey = weixinConfig['codeKey'];
         | 
| @@ -44,7 +47,10 @@ function weixinUrlCode(config) { | |
| 44 47 | 
             
                                hrefState = item.substr(6);
         | 
| 45 48 | 
             
                                var stateKey = weixinConfig['stateKey'] || "weixinState";
         | 
| 46 49 | 
             
                                w.sessionStorage.setItem(stateKey, hrefState);
         | 
| 47 | 
            -
                                 | 
| 50 | 
            +
                                var stateObj = (0, crypto_1.decrypt)(hrefState, cryptoConfig(cryptokey).key, cryptoConfig(cryptoiv).iv);
         | 
| 51 | 
            +
                                if (stateObj instanceof Object)
         | 
| 52 | 
            +
                                    stateObj = JSON.stringify(stateObj);
         | 
| 53 | 
            +
                                w.sessionStorage.setItem("".concat(stateKey, "Obj"), stateObj);
         | 
| 48 54 | 
             
                            }
         | 
| 49 55 | 
             
                        }
         | 
| 50 56 | 
             
                    }
         | 
| @@ -53,12 +59,11 @@ function weixinUrlCode(config) { | |
| 53 59 | 
             
                }
         | 
| 54 60 | 
             
            }
         | 
| 55 61 | 
             
            exports.weixinUrlCode = weixinUrlCode;
         | 
| 56 | 
            -
            function cryptoConfig() {
         | 
| 57 | 
            -
                 | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
                    key = weixinConfig.cryptokey;
         | 
| 62 | 
            +
            function cryptoConfig(key, iv) {
         | 
| 63 | 
            +
                if (!key)
         | 
| 64 | 
            +
                    key = defaultKey;
         | 
| 65 | 
            +
                if (!iv)
         | 
| 66 | 
            +
                    key = defaultIv;
         | 
| 62 67 | 
             
                return {
         | 
| 63 68 | 
             
                    key: key,
         | 
| 64 69 | 
             
                    iv: iv,
         | 
| @@ -218,7 +223,7 @@ function weixinShareInit(options) { | |
| 218 223 | 
             
                    var state = "";
         | 
| 219 224 | 
             
                    if (options === null || options === void 0 ? void 0 : options.data) {
         | 
| 220 225 | 
             
                        var data = options.data;
         | 
| 221 | 
            -
                        state = (0, crypto_1.encrypt)(data, options['key'], options['iv']);
         | 
| 226 | 
            +
                        state = (0, crypto_1.encrypt)(data, cryptoConfig(options['key']).key, cryptoConfig(options['iv']).iv);
         | 
| 222 227 | 
             
                        link = "".concat(link, "?state=").concat(state);
         | 
| 223 228 | 
             
                    }
         | 
| 224 229 | 
             
                }
         | 
    
        package/package.json
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            {
         | 
| 2 2 | 
             
              "name": "xctc-utils",
         | 
| 3 | 
            -
              "version": "1.1. | 
| 3 | 
            +
              "version": "1.1.4",
         | 
| 4 4 | 
             
              "description": "localStorage存储\r ```\r sessionStorage存储\r ```\r crypto-js加密、解密\r ```\r 微信授权登录、微信分享\r ```\r 设备环境获取\r ```\r 是否是微信浏览器\r ```\r 时间戳转时间,字符串转时间戳",
         | 
| 5 5 | 
             
              "main": "./dist/index.js",
         | 
| 6 6 | 
             
              "types": "./dist/index.d.ts",
         |