Repository: xulayen/wechat-sdk-gen
Branch: master
Commit: 3cee76a47e6b
Files: 7
Total size: 6.1 KB
Directory structure:
gitextract_ixkqkram/
├── .vscode/
│ └── launch.json
├── README.md
├── access_token/
│ └── webtoken.js
├── index.js
├── package.json
├── signature/
│ └── sign.js
└── ticket/
└── ticket.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .vscode/launch.json
================================================
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Electron Main",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"program": "${workspaceRoot}/main.js",
"protocol": "legacy"
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/index.js"
}
]
}
================================================
FILE: README.md
================================================
> *use wechat-sdk-gen to generate access_token and signature support*
## Installation
``` js
$ sudo npm install -g wechat-sdk-gen
$ npm install -g wechat-sdk-gen
```
## Usage
``` html
Usage: wsg [options]
Options:
-V, --version output the version number
-w, --wechatInfo [appid] [appsecrect] [timestamp] [nonceStr] [url] get access_token and signature support
-v, --version output the version number
-h, --help output usage information
```
================================================
FILE: access_token/webtoken.js
================================================
'use strict';
const request = require('request');
const qs = require('querystring');
const NodeCache = require( "node-cache" );
const myCache = new NodeCache();
function get_access_token(appId,appSecret){
let reqUrl = 'https://api.weixin.qq.com/cgi-bin/token?';
let params = {
appid: appId,
secret: appSecret,
grant_type: 'client_credential'
};
let options = {
method: 'get',
url: reqUrl+qs.stringify(params)
};
console.log('\x1B[32m%s \x1B[0m', 'get_access_token:'+options.url); //cyan
var accessToken=myCache.get('accessToken'+appId);
if(accessToken===undefined){
return new Promise((resolve, reject) => {
request(options, function (err, res, body) {
if (res) {
console.log('\x1B[32m%s \x1B[0m','get access info!')
console.log('\x1B[32m%s \x1B[0m',body);
myCache.set( "accessToken"+appId, body, 7200);
resolve(body);
} else {
console.log('\x1B[31m%s \x1B[0m',err);
reject(err);
}
});
})
}else{
return new Promise((resolve, reject)=>{
console.log('access_token is not expire!');
console.log(accessToken);
resolve(accessToken);
})
}
};
module.exports=get_access_token;
================================================
FILE: index.js
================================================
#!/usr/bin/env node
var program = require('commander');
var package = require('package')(module);
var access_token=require('./access_token/webtoken');
var getticket=require('./ticket/ticket');
var getsign=require('./signature/sign');
program
.version(package.version)
.option('-w, --wechatInfo [appid] [appsecrect] [timestamp] [nonceStr] [url]','get access_token and signature support')
.option('-v, --version','output the version number')
.parse(process.argv);
if(program.wechatInfo) {
var appid= process.argv.slice(2)[1];
var appsecrect= process.argv.slice(2)[2];
var timestamp= process.argv.slice(2)[3];
var nonceStr= process.argv.slice(2)[4];
var url= process.argv.slice(2)[5];
access_token(appid,appsecrect)
.then(function (data) {
var access=JSON.parse(data);
var access_token=access['access_token'];
getticket(appid,access_token).then(t => {
var sign=getsign(t.ticket,url,nonceStr,timestamp);
console.log('\x1B[35m%s \x1B[0m',JSON.stringify({access_token: access_token,signature:sign}));
})
});
}else{
//show help
}
================================================
FILE: package.json
================================================
{
"name": "wechat-sdk-gen",
"version": "1.0.5",
"description": "use wechat-sdk-gen to generate access_token and signature support",
"main": "index.js",
"bin": {
"wsg": "./index.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"cli",
"wechat",
"jsapi"
],
"git":"https://github.com/xulayen/wechat-sdk-gen.git",
"author": "xulayen",
"license": "ISC",
"dependencies": {
"commander": "^2.11.0",
"node-cache": "^4.1.1",
"package": "^1.0.1",
"querystring": "^0.2.0",
"request": "^2.83.0",
"sha1": "^1.1.1",
"shelljs": "^0.7.8"
}
}
================================================
FILE: signature/sign.js
================================================
'use strict';
const request = require('request');
const sha1 = require('sha1');
function getsignature(ticket,url,noncestr,timestamp){
var s='jsapi_ticket='+ticket+'&noncestr='+noncestr+'×tamp='+timestamp+'&url='+url;
return sha1(s);
};
module.exports=getsignature;
================================================
FILE: ticket/ticket.js
================================================
'use strict';
const request = require('request');
const qs = require('querystring');
const NodeCache = require( "node-cache" );
const myCache = new NodeCache();
function get_ticket(appId,access_token){
let reqUrl = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?';
let params = {
access_token: access_token,
type: 'jsapi'
};
let options = {
method: 'get',
url: reqUrl+qs.stringify(params)
};
console.log('\x1B[32m%s \x1B[0m','getticket:'+options.url);
var ticket=myCache.get('jsapi_ticket'+appId);
if(ticket===undefined){
return new Promise((resolve, reject) => {
request(options, function (err, res, body) {
if (res) {
console.log('\x1B[32m%s \x1B[0m','get ticket info!')
console.log('\x1B[32m%s \x1B[0m',body);
myCache.set( "jsapi_ticket"+appId, body, 7200);
resolve(body);
} else {
console.log('\x1B[31m%s \x1B[0m',err);
reject(err);
}
});
})
}else{
return new Promise((resolve, reject)=>{
console.log('\x1B[32m%s \x1B[0m','ticket is not expire!');
console.log('\x1B[32m%s \x1B[0m',ticket);
resolve(ticket);
})
}
};
module.exports=get_ticket;
gitextract_ixkqkram/
├── .vscode/
│ └── launch.json
├── README.md
├── access_token/
│ └── webtoken.js
├── index.js
├── package.json
├── signature/
│ └── sign.js
└── ticket/
└── ticket.js
SYMBOL INDEX (3 symbols across 3 files)
FILE: access_token/webtoken.js
function get_access_token (line 8) | function get_access_token(appId,appSecret){
FILE: signature/sign.js
function getsignature (line 6) | function getsignature(ticket,url,noncestr,timestamp){
FILE: ticket/ticket.js
function get_ticket (line 8) | function get_ticket(appId,access_token){
Condensed preview — 7 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (7K chars).
[
{
"path": ".vscode/launch.json",
"chars": 725,
"preview": "{\n // Use IntelliSense to learn about possible Node.js debug attributes.\n // Hover to view descriptions of existin"
},
{
"path": "README.md",
"chars": 633,
"preview": "> *use wechat-sdk-gen to generate access_token and signature support*\n\n## Installation\n\n``` js\n$ sudo npm install -g wec"
},
{
"path": "access_token/webtoken.js",
"chars": 1415,
"preview": "\n'use strict';\nconst request = require('request');\nconst qs = require('querystring');\nconst NodeCache = require( \"node-c"
},
{
"path": "index.js",
"chars": 1115,
"preview": "#!/usr/bin/env node\n\nvar program = require('commander');\nvar package = require('package')(module);\nvar access_token=requ"
},
{
"path": "package.json",
"chars": 644,
"preview": "{\n \"name\": \"wechat-sdk-gen\",\n \"version\": \"1.0.5\",\n \"description\": \"use wechat-sdk-gen to generate access_token and si"
},
{
"path": "signature/sign.js",
"chars": 279,
"preview": "\n'use strict';\nconst request = require('request');\nconst sha1 = require('sha1');\n\nfunction getsignature(ticket,url,nonce"
},
{
"path": "ticket/ticket.js",
"chars": 1386,
"preview": "\n'use strict';\nconst request = require('request');\nconst qs = require('querystring');\nconst NodeCache = require( \"node-c"
}
]
About this extraction
This page contains the full source code of the xulayen/wechat-sdk-gen GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 7 files (6.1 KB), approximately 1.8k tokens, and a symbol index with 3 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.