Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/favor-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { Goofish } = require('goofish-client');

// 初始化客户端(需要有效的cookie)
const client = new Goofish({
cookie: 'cookie2=xxx',
// cookie: 'cookie2=xxx',
});

async function favorExamples() {
Expand Down
2 changes: 1 addition & 1 deletion examples/home-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { Goofish } = require('goofish-client');
async function homeFeedExample() {
// 创建客户端实例
const client = new Goofish({
cookie: 'cookie2=xxx', // 设置你的cookie
// cookie: 'cookie2=xxx', // 设置你的cookie
});

try {
Expand Down
2 changes: 1 addition & 1 deletion examples/im.simple.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { Goofish, LogLevel } = require('goofish-client');
async function imSimpleExample() {
try {
const client = new Goofish({
cookie: 'xxx', // 请替换为实际的 cookie
// cookie: 'xxx', // 请替换为实际的 cookie
level: LogLevel.WARN,
});

Expand Down
2 changes: 1 addition & 1 deletion examples/item-detail-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { Goofish } = require('goofish-client');

async function getItemDetail() {
const client = new Goofish({
cookie: 'cookie2=xxx',
// cookie: 'cookie2=xxx',
});

try {
Expand Down
2 changes: 1 addition & 1 deletion examples/order-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { Goofish } = require('goofish-client');

// 初始化客户端(需要有效的cookie)
const client = new Goofish({
cookie: 'cookie2=xxx',
// cookie: 'cookie2=xxx',
});

async function orderExamples() {
Expand Down
2 changes: 1 addition & 1 deletion examples/password-login-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ async function passwordLogin() {
// 创建 Client 实例
const client = new Goofish({
// 过滑块验证码的cookie,cookie具有时效性,需要定期更新
cookie: 'x5sec=',
// cookie: 'x5sec=',
level: LogLevel.INFO,
});

Expand Down
2 changes: 1 addition & 1 deletion examples/search-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ async function searchItems() {
try {
// 创建 Client 实例
const client = new Goofish({
cookie: 'cookie2=xxxx',
// cookie: 'cookie2=xxxx',
level: LogLevel.INFO,
});

Expand Down
2 changes: 1 addition & 1 deletion examples/user-detail-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { Goofish } = require('goofish-client');
async function getUserDetail() {
// 创建Client实例
const client = new Goofish({
cookie: 'cookie2=xxx',
// cookie: 'cookie2=xxx',
});

try {
Expand Down
2 changes: 1 addition & 1 deletion examples/user-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ async function getUserInfo() {
try {
// 创建 Client 实例
const client = new Goofish({
cookie: 'cookie2=xxxx',
// cookie: 'cookie2=xxxx',
level: LogLevel.INFO,
});

Expand Down
4 changes: 2 additions & 2 deletions src/client/goofish.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type { GoofishConfig } from '../types';
import { QrService } from '../services/passport/qr.service';
import { LoginService } from '../services/passport/login.service';
import { HomeService } from '../services/mtop';
import { generateUUID } from '../utils';
import { generateUUID, generateSecureRandomString } from '../utils';
import { AuthService } from '../services/im';

export class Goofish {
Expand Down Expand Up @@ -87,7 +87,7 @@ export class Goofish {

this.config = {
level: config.level || LogLevel.INFO,
cookie: config.cookie || '',
cookie: config.cookie || `cna=${generateSecureRandomString(24)}`,

// Mtop 配置
mtop: {
Expand Down
12 changes: 12 additions & 0 deletions src/utils/sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,15 @@ export function generateUUID(): string {

return uuid.join('');
}
/**
* 生成指定长度的随机字符串
*/
export function generateSecureRandomString(length: number): string {
const chars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
return result;
}
Loading