A preliminary understanding of paid knowledge points and a preliminary understanding of knowledge points
Go to the official website to register an account and create an app merchant platform. Merchants can view some transaction records and balance withdrawal. The website provided by the open platform for developers must use the payment function first.If you open the platform to apply for an account, these steps will not be discussed here. After successful registration, you will receive an email and go to the merchant platform for key settings. With an account, you can create an application to obtain our AppID and activate the payment capability, for example:
Enter the Development Information. Here, the signature and package name of the application are required.The applicationId in build. gradle can be obtained through the signature tool.
Take a look at the official payment process
Now you only need to generate an order (usually operations performed on the server) and then initiate a payment request to make the payment.
Construct order information
Unified order: the requested interface generates a payment order. After the request is successful, the parameters required for initiating the request are returned.
Now you can integrate the payment SDK with the android access guide. Add the following dependency to the build. gradle file:
Dependencies {compile 'com. tencent. mm. opensdk: wechat-sdk-android-with-mta: + '// contains statistics} or dependencies {compile 'com. tencent. mm. opensdk: wechat-sdk-android-without-mta: + '// does not contain the statistics function}
Add required permission support to Manifest. xml:
The next step is to enable the App to pay for the payment interface.
ClientImportant code
// Register the app with IWXAPI api = wxapifacloud. createWXAPI (this, "APP_ID"); api. registerApp ("APP_ID"); // create the payment object information PayReq req = new PayReq (); req. appId = "APP_ID"; // use the account on the open platform to log on to the merchant platform and go to the account center-> merchant information to see the req. partnerId = "Merchant ID"; // The return payment transaction address IDreq. prepayId = "wx20170923578829050ad2bea30542412476"; // a random string of no more than 32 characters. Req. nonceStr = String. valueOf (System. currentTimeMillis (); // it needs to be converted to second (10 digits) req. timeStamp = System. currentTimeMillis ()/1000 + ""; req. packageValue = "Sign = WXPay"; // generate a req Based on the signature algorithm provided on the official website. sign = ""; // I do not know what it is for now, but it must be filled in. Here we copy the req in the Demo. extData = "app data"; // before payment, if the application is not registered, call the api first. registerApp registers the application to the api. sendReq (req );
Receive the payment result using the officialWXPayEntryActivity. java is enough. Remember to register this Activity.
/*** Receive payment result */public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {private IWXAPI api; @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); api = wxapifacloud. createWXAPI (this, PayInfoMsg. CX_APP_ID); api. handleIntent (getIntent (), this) ;}@ Override protected void onNewIntent (Intent intent) {super. onNewIntent (intent); setIntent (intent); api. handleIntent (intent, this) ;}@ Override public void onReq (BaseReq req) {}@ Override public void onResp (BaseResp resp) {if (resp. errCode = BaseResp. errCode. ERR_USER_CANCEL) {ToastUtils. showcancsafe ("Payment canceled");} else if (resp. errCode = BaseResp. errCode. ERR_ OK) {ToastUtils. showdomainsafe ("Payment successful");} Log. e ("payment, errCode =" + resp. errCode); finish ();}}
Conclusion: All important operations are to generate an order on the server side, and then get the returned data to initiate App payment; therefore, there is basically no operation on the client side. You only need to initiate a request and then process the payment result.