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 correct, but you do not know that the keystore we pack is different from the md5 value of the program signature obtained by the packaged keystore. 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
,
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:
[Java]
Private Button btn_share;
Public static final String WX_APP_ID = "wxc85b9dbef61b3fe4 ";
Private IWXAPI api;
Private String text = "testssss ";
@ Override
Public void onCreate (BundlesavedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
Btn_share = (Button) findViewById (R. id. btn_share );
Api = wxapifacloud. createWXAPI (this, WX_APP_ID, false );
Btn_share.setOnClickListener (new 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
Api. sendReq (req );
Finish ();
}
});
}
Private StringbuildTransaction (finalString type ){
Return (type = null )? String. valueOf (System. currentTimeMillis ())
: Type + System. currentTimeMillis ();
}
Private Button btn_share;
Public static final String WX_APP_ID = "wxc85b9dbef61b3fe4 ";
Private IWXAPI api;
Private String text = "testssss ";
@ Override
Public void onCreate (BundlesavedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
Btn_share = (Button) findViewById (R. id. btn_share );
Api = wxapifacloud. createWXAPI (this, WX_APP_ID, false );
Btn_share.setOnClickListener (new 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
Api. sendReq (req );
Finish ();
}
});
}
Private StringbuildTransaction (finalString type ){
Return (type = null )? String. valueOf (System. currentTimeMillis ())
: Type + System. currentTimeMillis ();
} Www.2cto.com
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