Android payment and android email payment
========================================================== =
Preparation:
1. The imported libs package libammsdk. jar;
2. Use debug_keystore in weixinDemo for testing;
3. Pay attention that the application must pass the review and the Key values are correct. The values in the payment Demo are as follows:
// Public platform id; private String app_wx_appid = WxConstants. app_wx_appid; // private String app_wx_secret_key = "secret" agreed by the open platform and merchants; // private String app_wx_parent_key = "secret" agreed by the merchant module of the public platform and the merchant "; // The payment key private String app_wx_pay_key = "yellow" agreed by the merchant module of the public platform and the merchant; // The Merchant id applied by the merchant to caifu */private String app_tx_parent_key = "1900000109 ";
========================================================== =
Based on the Payment Demo, the payment is divided into three steps:
Step 1: Obtain the accessToken and use the accessToken value in step 2;
private class GetAccessTokenTask extends AsyncTask<Void, Void, WxGetAccessTokenResult> {@Overrideprotected WxGetAccessTokenResult doInBackground(Void... params) {WxGetAccessTokenResult result = getAccessToken();return result;}@Overrideprotected void onPostExecute(WxGetAccessTokenResult result) {if (result.localRetCode == WxLocalRetCode.ERR_OK) {GetPrepayIdTask getPrepayId = new GetPrepayIdTask();getPrepayId.execute(result);}}}
Resolution Server Response
private WxGetAccessTokenResult getAccessToken() {WxGetAccessTokenResult result = new WxGetAccessTokenResult();String url = String.format(api_get_access_token, "client_credential",app_wx_appid, app_wx_secret_key);byte[] buf = WeixinUtil.httpGet(url);if (buf == null || buf.length == 0) {result.localRetCode = WxLocalRetCode.ERR_HTTP;return result;}String content = new String(buf);result.parseFrom(content);return result;}
Step 2: Post the assembled product parameters to the server based on the accesstoken value of step 1.
private class GetPrepayIdTask extends AsyncTask<WxGetAccessTokenResult, Void, WxGetPrepayIdResult> {@Overrideprotected WxGetPrepayIdResult doInBackground(WxGetAccessTokenResult... params) {WxGetPrepayIdResult result = getPrepayId(params[0]);return result;}@Overrideprotected void onPostExecute(WxGetPrepayIdResult result) {if (result.localRetCode == WxLocalRetCode.ERR_OK) {sendPayReq(result);}}}
Assembly Parameters
private WxGetPrepayIdResult getPrepayId(WxGetAccessTokenResult accessTokenResult) {String url = String.format(api_get_preorder_id,accessTokenResult.accessToken);String entity = appSign.getWxPrepayAppSign();WxGetPrepayIdResult result = new WxGetPrepayIdResult();byte[] buf = WeixinUtil.httpPost(url, entity);if (buf == null || buf.length == 0) {result.localRetCode = WxLocalRetCode.ERR_HTTP;return result;}String content = new String(buf);result.parseFrom(content);return result;}
Post to server
<span style="white-space:pre"></span>private void sendPayReq(WxGetPrepayIdResult result) {PayReq req = new PayReq();req.appId = app_wx_appid;req.partnerId = app_tx_parent_key;req.prepayId = result.prepayId;req.nonceStr = appSign.getNoncestr();req.timeStamp = appSign.getTimestamp();req.packageValue = "Sign=" + appSign.getPackageSign();List<NameValuePair> signParams = new LinkedList<NameValuePair>();signParams.add(new BasicNameValuePair("appid", req.appId));signParams.add(new BasicNameValuePair("appkey", app_wx_pay_key));signParams.add(new BasicNameValuePair("noncestr", req.nonceStr));signParams.add(new BasicNameValuePair("package", req.packageValue));signParams.add(new BasicNameValuePair("partnerid", req.partnerId));signParams.add(new BasicNameValuePair("prepayid", req.prepayId));signParams.add(new BasicNameValuePair("timestamp", req.timeStamp));req.sign = WeixinUtil.genSign(signParams);wxRequest.sendReq(req);}
Step 3: Create a package wxapi under the project and create a class named WXPayEntryActivity as the payment result. However, the final result is subject to the returned result of the server, policy_url:
Package net. sourceforge. simcpux. wxapi; public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {<pre name = "code" class = "java"> <span style = "white-space: pre "> </span> @ Overridepublic void onResp (BaseResp resp) {Log. d (TAG, "onPayFinish, errCode =" + resp. errCode); if (resp. getType () = ConstantsAPI. COMMAND_PAY_BY_WX) {AlertDialog. builder builder = new AlertDialog. builder (this); builder. setTitle ("Payment result"); builder. setMessage ("Payment result" + String. valueOf (resp. errCode); builder. show ();}}
}
========================================================== =
For the moment, I did not expect other things to be said. Let's take a look at the effect first.
1. In the package structure, note the class name that receives the returned results;
2. Assemble data. The rules are described in this document.
// Package _ field generation method // package generation method: // A) After all input parameters are sorted in ascending order (lexicographically) according to the ASCII code of field names, format of the URL key-Value Pair (that is, key1 = value1 & key2 = value2 ...) Concatenate the string into string1; // B) obtain the stringSignTemp string by key = partnerKey at the end of string1, perform md5 operations on stringSignTemp, and convert all the characters in the string to uppercase, obtain the signValue of sign. // C) perform urlencode transcoding on the values of all key-value pairs in string1, resplice them into strings according to step a, and get string2. For js frontend programs, you must use the encodeURIComponent function for urlencode encoding (note! During urlencode, convert the space to % 20 instead of + ). // D) concatenate sign = signValue into string1 to obtain the final package string. // App_signature generation method: // A) signature fields include: appid, appkey, noncestr, package, timestamp, and traceid // B) after all parameters to be signed are sorted in ascending order (lexicographically) according to the field name ASCII code, the format of the URL key-value pair is used (that is, key1 = value1 & key2 = value2 ...) Concatenate the string into string1. Note: All parameter names are lowercase characters. // C) use the string1 signature algorithm. Both field names and Field Values use the original values without URL escaping. The specific signature algorithm is sha1.
3. corresponding payment Interface
What are the benefits of payment?
1. Free text message: the extremely fast and free floor-style text message conversation brings you an amazing mobile phone chat experience.
2. photo sharing: You can use your mobile phone to take a photo or insert an album image. You do not have to pay for MMS when you send any photo.
3. Set Avatar: Set personalized Avatar for yourself to make your friends look more friendly.
4. Real-time status: if a friend is sending you a message, the status of "the other party is inputting..." is displayed.
5. Fully supports multiple devices such as IPHONE, Android, and Symbian.
Why can't I pay for qcoins for Android?
Hello, yes. Currently, this type of recharge is not supported. If you have any questions, follow up. If you are satisfied with my reply, please choose "adopt". This will encourage us to better answer questions from other netizens. Thank you.