[
  {
    "path": ".vscode/launch.json",
    "content": "{\n    // Use IntelliSense to learn about possible Node.js debug attributes.\n    // Hover to view descriptions of existing attributes.\n    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\n    \"version\": \"0.2.0\",\n    \"configurations\": [\n        {\n            \"type\": \"node\",\n            \"request\": \"launch\",\n            \"name\": \"Electron Main\",\n            \"runtimeExecutable\": \"${workspaceRoot}/node_modules/.bin/electron\",\n            \"program\": \"${workspaceRoot}/main.js\",\n            \"protocol\": \"legacy\"\n        },\n        {\n            \"type\": \"node\",\n            \"request\": \"launch\",\n            \"name\": \"Launch Program\",\n            \"program\": \"${workspaceRoot}/index.js\"\n        }\n    ]\n}"
  },
  {
    "path": "README.md",
    "content": "> *use wechat-sdk-gen to generate access_token and signature support*\n\n## Installation\n\n``` js\n$ sudo npm install -g wechat-sdk-gen\n\n$ npm install -g wechat-sdk-gen\n```\n\n## Usage\n\n``` html\n  Usage: wsg [options]\n\n\n  Options:\n\n    -V, --version                                                       output the version number\n    -w, --wechatInfo [appid] [appsecrect] [timestamp] [nonceStr] [url]  get access_token and signature support\n    -v, --version                                                       output the version number\n    -h, --help                                                          output usage information\n```"
  },
  {
    "path": "access_token/webtoken.js",
    "content": "\n'use strict';\nconst request = require('request');\nconst qs = require('querystring');\nconst NodeCache = require( \"node-cache\" );\nconst myCache = new NodeCache();\n\nfunction get_access_token(appId,appSecret){\n    let reqUrl = 'https://api.weixin.qq.com/cgi-bin/token?';\n    let params = {\n        appid: appId,\n        secret: appSecret,\n        grant_type: 'client_credential'\n    };\n\n    let options = {\n        method: 'get',\n        url: reqUrl+qs.stringify(params)\n    };\n    console.log('\\x1B[32m%s \\x1B[0m', 'get_access_token：'+options.url);  //cyan  \n    var accessToken=myCache.get('accessToken'+appId);\n    if(accessToken===undefined){\n        return new Promise((resolve, reject) => {\n            request(options, function (err, res, body) {\n                if (res) {\n                    console.log('\\x1B[32m%s \\x1B[0m','get access info!')\n                    console.log('\\x1B[32m%s \\x1B[0m',body);\n                    myCache.set( \"accessToken\"+appId, body, 7200);\n                    resolve(body);\n                } else {\n                    console.log('\\x1B[31m%s \\x1B[0m',err);\n                    reject(err);\n                }\n            });\n        })\n    }else{\n        return new Promise((resolve, reject)=>{\n            console.log('access_token is not expire!');\n            console.log(accessToken);\n            resolve(accessToken);\n        })\n    }\n};\nmodule.exports=get_access_token;\n"
  },
  {
    "path": "index.js",
    "content": "#!/usr/bin/env node\n\nvar program = require('commander');\nvar package = require('package')(module);\nvar access_token=require('./access_token/webtoken');\nvar getticket=require('./ticket/ticket');\nvar getsign=require('./signature/sign');\n\nprogram\n  .version(package.version)\n  .option('-w, --wechatInfo [appid] [appsecrect] [timestamp] [nonceStr] [url]','get access_token and signature support')\n  .option('-v, --version','output the version number')\n  .parse(process.argv);\n\nif(program.wechatInfo) {\n    var appid= process.argv.slice(2)[1];\n    var appsecrect= process.argv.slice(2)[2];\n    var timestamp= process.argv.slice(2)[3];\n    var nonceStr= process.argv.slice(2)[4];\n    var url= process.argv.slice(2)[5];\n    access_token(appid,appsecrect)\n    .then(function (data) {\n      var access=JSON.parse(data);\n      var access_token=access['access_token'];\n      getticket(appid,access_token).then(t => {\n          var sign=getsign(t.ticket,url,nonceStr,timestamp);\n          console.log('\\x1B[35m%s \\x1B[0m',JSON.stringify({access_token: access_token,signature:sign}));\n      })\n    });\n}else{\n    //show help \n}\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"wechat-sdk-gen\",\n  \"version\": \"1.0.5\",\n  \"description\": \"use wechat-sdk-gen to generate access_token and signature support\",\n  \"main\": \"index.js\",\n  \"bin\": {\n    \"wsg\": \"./index.js\"\n  },\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n  },\n  \"keywords\": [\n    \"cli\",\n    \"wechat\",\n    \"jsapi\"\n  ],\n  \"git\":\"https://github.com/xulayen/wechat-sdk-gen.git\",\n  \"author\": \"xulayen\",\n  \"license\": \"ISC\",\n  \"dependencies\": {\n    \"commander\": \"^2.11.0\",\n    \"node-cache\": \"^4.1.1\",\n    \"package\": \"^1.0.1\",\n    \"querystring\": \"^0.2.0\",\n    \"request\": \"^2.83.0\",\n    \"sha1\": \"^1.1.1\",\n    \"shelljs\": \"^0.7.8\"\n  }\n}\n"
  },
  {
    "path": "signature/sign.js",
    "content": "\n'use strict';\nconst request = require('request');\nconst sha1 = require('sha1');\n\nfunction getsignature(ticket,url,noncestr,timestamp){\n    var s='jsapi_ticket='+ticket+'&noncestr='+noncestr+'&timestamp='+timestamp+'&url='+url;\n    return sha1(s);\n};\nmodule.exports=getsignature;"
  },
  {
    "path": "ticket/ticket.js",
    "content": "\n'use strict';\nconst request = require('request');\nconst qs = require('querystring');\nconst NodeCache = require( \"node-cache\" );\nconst myCache = new NodeCache();\n\nfunction get_ticket(appId,access_token){\n    let reqUrl = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?';\n    let params = {\n        access_token: access_token,\n        type: 'jsapi'\n    };\n\n    let options = {\n        method: 'get',\n        url: reqUrl+qs.stringify(params)\n    };\n    console.log('\\x1B[32m%s \\x1B[0m','getticket:'+options.url);\n    var ticket=myCache.get('jsapi_ticket'+appId);\n    if(ticket===undefined){\n        return new Promise((resolve, reject) => {\n            request(options, function (err, res, body) {\n                if (res) {\n                    console.log('\\x1B[32m%s \\x1B[0m','get ticket info!')\n                    console.log('\\x1B[32m%s \\x1B[0m',body);\n                    myCache.set( \"jsapi_ticket\"+appId, body, 7200);\n                    resolve(body);\n                } else {\n                    console.log('\\x1B[31m%s \\x1B[0m',err);\n                    reject(err);\n                }\n            });\n        })\n    }else{\n        return new Promise((resolve, reject)=>{\n            console.log('\\x1B[32m%s \\x1B[0m','ticket is not expire!');\n            console.log('\\x1B[32m%s \\x1B[0m',ticket);\n            resolve(ticket);\n        })\n    }\n};\nmodule.exports=get_ticket;\n"
  }
]