Giter Club home page Giter Club logo

Comments (4)

xu-li avatar xu-li commented on May 29, 2024

@acylum It's based on OAuth 2, so you can get the access token and then request for user id and user name. A similar example would be 网页授权获取用户基本信息.

// Not tested.
Wechat.auth(scope, function (response) {
    // $ = jQuery
    var appId = "YOUR_APP_ID";
    var appSecret = "YOUR_APP_SECRET";
    $.get('https://api.weixin.qq.com/sns/oauth2/access_token?appid=' + appId + '&secret=' + appSecret + '&code=' + response.code + '&grant_type=authorization_code', function (accessTokenResponse) {
        // you should save access token response somewhere, e.g. cookies, local storage, etc.
        var accessToken = accessTokenResponse.access_token;
        var openId = accessTokenResponse.openid;

        // get user information
        $.get("https://api.weixin.qq.com/sns/userinfo?access_token=' + accessToken + '&openid=' + openId + '&lang=zh_CN", function (userInfoResponse) {
            console.log(userInfoResponse);
        });
    });
});

from cordova-plugin-wechat.

acylum avatar acylum commented on May 29, 2024

Great! Thanks! My next question - let's say I use the webAPI to refresh the access token (i.e. https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=APPID&grant_type=refresh_token&refresh_token=REFRESH_TOKEN).

How would I make your cordova-wechat plugin use this refreshed access-token (to do posts, etc,..)?

from cordova-plugin-wechat.

xu-li avatar xu-li commented on May 29, 2024

@acylum Refresh token will be available in the access token response. See 网页授权获取用户基本信息.

from cordova-plugin-wechat.

YuyangHYY avatar YuyangHYY commented on May 29, 2024
[11:27:43]  tslint: src/app/app.component.ts, line: 169
            'accessToken' is declared but never used.

     L168:  // you should save access token response somewhere, e.g. cookies, local storage, etc.
     L169:  var accessToken = accessTokenResponse.access_token;
     L170:  var openId = accessTokenResponse.openid;

[11:27:43]  tslint: src/app/app.component.ts, line: 170
            'openId' is declared but never used.

     L169:  var accessToken = accessTokenResponse.access_token;
     L170:  var openId = accessTokenResponse.openid;
     L171:  // get user information

When I run it in web browser with ionic serve -l , this warning coming out. And I am using ionic3

ionic info

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.16.0
    ionic (Ionic CLI) : 3.16.0

global packages:

    cordova (Cordova CLI) : 7.0.1

local packages:

    @ionic/app-scripts : 2.1.3
    Cordova Platforms  : android 6.3.0 ios 4.4.0
    Ionic Framework    : ionic-angular 3.6.0

System:

    ios-deploy : 1.9.2
    Node       : v6.11.3
    npm        : 3.10.10
    OS         : macOS Sierra
    Xcode      : Xcode 8.3.3 Build version 8E3004b

Environment Variables:

    ANDROID_HOME : not set

Misc:

    backend : pro

from cordova-plugin-wechat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.