Android implementation Micro-letter Login Detailed _android

Source: Internet
Author: User

Objective

The function of sharing to the micro-trust friends Circle has already been, but the micro-letter login launch and soon, the document is not very clear, the record is shared here.

Body

First, prepare

Registration, certification steps to themselves. Micro-Letter Open platform: https://open.weixin.qq.com

Second, the Code

2.1 Evoke micro-letter Login

Reference official Website Documentation: Resource Center/Mobile Application Open/Access Guide/android Access Guide

Private Iwxapi Mweixinapi;

  private void Loginwithweixin () {
    if (Mweixinapi = = null) {
      MWEIXINAPI = Wxapifactory.createwxapi (This, weixin_ APP_ID, false);

    if (!mweixinapi.iswxappinstalled ()) {
      //remind the user not to follow the micro-letter return
      ;
    }

    Mweixinapi.registerapp (weixin_app_id);

    Sendauth.req Req = new Sendauth.req ();
    Req.scope = Weixin_scope;
    Req.state = weixin_state;
    Mweixinapi.sendreq (req);
  }

wexin_scope: here fill in the Snsapi_userinfo, with snsapi_base hint does not have permission.

weixin_state: is used to maintain the state of the request and callback, and the authorization request is brought back to the third party as is. This parameter can be used to prevent CSRF attacks (cross-station request forgery attacks), it is recommended that a third party with this parameter, can be set to a simple random number plus session for verification.

No accident can arouse the micro-letter login.

2.2 Request and return value of receiving micro-letter

Create a new WXAPI directory under your package name and add a wxentryactivity class to the WXAPI directory to register the activity in Androidmanifest.xml.

public class Wxentryactivity extends activity {

  @Override
  protected void onCreate (Bundle savedinstancestate) { C4/>super.oncreate (savedinstancestate);

    Handleintent (Getintent ());
  }

  @Override
  protected void onnewintent (Intent Intent) {
    super.onnewintent (Intent);
    Handleintent (intent);
  }

  private void Handleintent (Intent Intent) {
    Sendauth.resp Resp = new Sendauth.resp (Intent.getextras ());
    if (Resp.errcode = = BaseResp.ErrCode.ERR_OK) {
      //user Consent
    }}
  }

Note: here is a bit different from the micro-letter example, but the result is the same, this can take the code and other information, test return data as follows:

 E/wxentryactivity (14288): oncreate...key:_wxapi_sendauth_resp_state xxx e/wxentryactivity (14288): onCreate...key:_ Wxapi_sendauth_resp_token xxxxxxxxxxxxxxxxxxxxxxxxxxxxx e/wxentryactivity (14288): OnCreate...key:_mmessage_ Apppackage com.tencent.mm e/wxentryactivity (14288): oncreate...key:_wxapi_baseresp_transaction null E/wxentryactiv ity (14288): Oncreate...key:_wxapi_sendauth_resp_lang zh_cn e/wxentryactivity (14288): OnCreate...key:_wxapi_command _type 1 e/wxentryactivity (14288): oncreate...key:_mmessage_content null e/wxentryactivity (14288): onCreate...key:_ Wxapi_sendauth_resp_country null e/wxentryactivity (14288): oncreate...key:_mmessage_checksum [B@426358e8 E/WXEntry Activity (14288): Oncreate...key:wx_token_key com.tencent.mm.openapi.token e/wxentryactivity (14288): Oncreate...key : _wxapi_sendauth_resp_url xxxxxxxxxxx e/wxentryactivity (14288): Oncreate...key:_mmessage_sdkversion 570490883 Entryactivity (14288): Oncreate...key:_wxapi_bAseresp_errcode 0 e/wxentryactivity (14288): oncreate...key:_wxapi_baseresp_errstr null e/wxentryactivity (14288): o Ncreate...key:_wxapi_baseresp_openid NULL

XXX Part of the content I have hidden away, get code can get Access--token, follow the document call can.

Here you can make the wxentryactivity theme transparent, and then bounce up a progressdialog for subsequent operations (submit your own server), you can fully integrate with the existing interface.

Third, Attention:

3.1 Obtain the signature must use the release package. (So you'll find that the micro-mail, micro-blogging SDK Gets the same value, so if you already have a Weibo signature, you can copy it directly to the micro-mail.)

Above the Android micro-letter login to share the function of the circle of friends, there is a need for friends to see.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.