Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用api_js时重复请求access_token和js_api_ticket #171

Open
ghost opened this issue Aug 7, 2016 · 0 comments
Open

使用api_js时重复请求access_token和js_api_ticket #171

ghost opened this issue Aug 7, 2016 · 0 comments

Comments

@ghost
Copy link

ghost commented Aug 7, 2016

const accessToken = (callback) => {
    Fiber(() => {
        const accessToken = AppState.find({stateName: wechatJsSdk.token}).fetch();
        console.log(`accessToken ${JSON.stringify(accessToken)}`);
        callback(null, accessToken);
    }).run();
};
const updateToken= (token, callback) => {
    Fiber(() => {
        console.log(`updateToken ${JSON.stringify(token)}`);
        AppState.upsert({stateName: wechatJsSdk.token}, { $set: token});
        callback(null);
    }).run();
};

const api = new WechatAPI(
    Meteor.settings.weChatMp.appId,
    Meteor.settings.weChatMp.appSecret,
    accessToken,
    updateToken
);

const getTicketToken = (type, callback) => {
    Fiber(() => {
        const ticket = AppState.find({stateName: wechatJsSdk.ticket}).fetch();
        console.log(`getTicketToken ${JSON.stringify(ticket)}`);
        callback(null, ticket);
        return ticket;
    }).run();
};
const saveTicketToken = (type, ticketToken) => {
    Fiber(() => {
        console.log(`saveTicketToken ${JSON.stringify(ticketToken)}`);
        AppState.upsert({stateName: wechatJsSdk.ticket}, { $set: ticketToken} );
    }).run();
};


const getTicket = (err, result) => {
    Fiber(() => {
        console.log(`getTicket ${JSON.stringify(result)}`);
        if (!err) {
            AppState.upsert({stateName: wechatJsSdk.ticket}, { $set: result } );
        }
    }).run();
};

//如果执行这两行,
//api.registerTicketHandle(getTicketToken, saveTicketToken);
//api.getTicket(wechatJsSdk.ticket, getTicket);
//那这行没有返回结果. 而且access token 和 ticket 都会刷新两次以上。
//api.getJsConfig(param, callback);

具体问题就是这样的。请问这个API是这样用吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants