Android WeChat sdk api call tutorial

Source: Internet
Author: User

The APIs that have been being called recently are found to be unsuccessful and have been entangled for a long time. For more information, see tutorials and official documents, three steps are required.

1. Apply for app_id

2. Enter the package name. 3,

Obtain the MD5 value of the program signature,

You can call these three steps as long as you are right, but you do not know that sometimesThe keystore called by eclipse is different from the MD5 of the program signature obtained by the packaged keystore. In addition, the APK value generated for each keystore is different.. The program signature value we entered during the application was officially packaged, But we deployed it in eclipse using our default debug. keystore. the consequence of this is that the program signature is different and cannot be called. We don't even know where we are wrong.

Let's talk about how to deploy the demo on the official website: [The content referenced below is the official website]

Strict verification is required for Android API calls. It can be called only when the app_id package name and the program signature are correct.

How to run the sdkdemo Project

 

1. decompress the SDK Demo project package and import it to the workspace, for example:

 

2. Select WINDOW> preferences in the top menu of eclipse. In the displayed dialog box, select build under the android directory, for example:

 

 

Specify the path of the custom debugkeystore option as the debug. keystore file in the SDK Demo project directory, for example:

And apply the configuration.

 

3. Run the sdk_sample project.

 

Now, let's go through the demo in the above three steps. Now let's take a look at our own demo.

1. Custom debugkeystore: replace it with our own keystore

 

For convenience, you can directly copy the default debug keystore above, and then proceed to step 2.

2. Install our app on your mobile phone and download an APK input package name that obtains the MD5 value of the program signature on the official website:

 

3. Go to the background to apply for our debugging application:

 

Then write the code in the sample code:

Private button btn_share; public static final string wx_app_id = "wxc85b9dbef61b3fe4"; private iwxapi API; private string text = "testssss"; @ override public void oncreate (bundlesavedinstancestate. oncreate (savedinstancestate); setcontentview (R. layout. main); btn_share = (button) findviewbyid (R. id. btn_share); API = wxapifacloud. createwxapi (this, wx_app_id, false); btn_assist.setonclicklistener (ne W onclicklistener () {@ override public void onclick (view v) {API. registerapp (wx_app_id); // initialize a wxtextobject object wxtextobjecttextobj = newwxtextobject (); textobj. TEXT = text; // use the wxtextobject object to initialize a wxmediamessage object wxmediamessagemsg = newwxmediamessage (); MSG. mediaobject = textobj; // when a text message is sent, the title field does not work MSG. title = "will be ignored"; MSG. description = "sdddd"; // construct a req sendmessagetowx. reqreq = Newsendmessagetowx. req (); req. transaction = buildtransaction ("text"); // The transaction field uniquely identifies a request req. message = MSG; // req. scene = sendmessagetowx. req. wxscenetimeline; // call the API to send data to the API. sendreq (req); finish () ;}}) ;}private stringbuildtransaction (finalstring type) {return (type = NULL )? String. valueof (system. currenttimemillis (): Type + system. currenttimemillis ();}

So far, the success is achieved.Do not forget the keysotre used in your program package and use the provided program to package and obtain the signature. It is different from the signature obtained in the eclpise program deployment.We can apply for another formal application, and the information can be exactly the same, but we only need to change it

And your app_id

Get program signature tool: http://open.weixin.qq.com/download/sdk/gen_signature.apk

I don't know if anyone can see it. If you have any questions, add me. I hope this article will help Android code farmers who are using APIs.

If you need to reprint reference please indicate the source: http://blog.csdn.net/jiahui524

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.