Access to UnionPay payment

Keywords: Android Mobile xml

Official documents can't be read. I access them based on video demo.
The access is mobile control payment, and the address is as follows:
https://open.unionpay.com/tjweb/acproduct/list?apiservId=450&tdsourcetag=s_pctim_aiomsg

1. Import UPPayAssistEx.jar and UPPayPluginExPro.jar into libs

2. Android manifest.xml configuration

<uses-permission android:name="org.simalliance.openmobileapi.SMARTCARD" />

<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="android.hardware.nfc.hce"/>
<activity
android:name="com.unionpay.uppay.PayActivity"
android:configChanges="orientation|keyboardHidden|keyboard"
android:screenOrientation="portrait">
</activity>

<activity
android:name="com.unionpay.UPPayWapActivity"
android:configChanges="orientation|keyboardHidden|fontScale"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize" >
</activity>

3. Call and callback

Call on one line of code:
//"00" - start the official environment of UnionPay "01" - connect the test environment of UnionPay
//The tn interface returns to the server. It's the best if there's any return, no request http://101.231.204.84:8091/sim/getacptn (official test request address)

UPPayAssistEx.startPay(mContext, null, null, tn,01);
Callback (official demo code includes):

     @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (data == null) {
return;
}

String msg = "";
/*
 * Payment control return string: success, fail and cancel respectively represent payment success, payment failure and payment cancellation
 */
String str = data.getExtras().getString("pay_result");
if (str.equalsIgnoreCase("success")) {
    
// If you want to check the signature of the result data, you can use the following code, but it is recommended not to check the signature, go directly to the merchant background to query the transaction result
// See c) result data parameter description for the result data structure
if (data.hasExtra("result_data")) {
String result = data.getExtras().getString("result_data");
try {
JSONObject resultJson = new JSONObject(result);
String sign = resultJson.getString("sign");
String dataOrg = resultJson.getString("data");
// verify here suggests sending it to the merchant background for signature verification
// To put it on the mobile terminal, the code must support updating the certificate 
boolean ret = verify(dataOrg, sign, mMode);
if (ret) {
// Successful signature verification, display payment result
msg = "Payment succeeded!";
} else {
// Failure of verification
msg = "Payment failed!";
}
} catch (JSONException e) {
}
} 
// If the result ﹣ data is successful, go to the merchant's background to check and show the success
msg = "Payment succeeded!";
} else if (str.equalsIgnoreCase("fail")) {
msg = "Payment failed!";
} else if (str.equalsIgnoreCase("cancel")) {
msg = "Payment cancelled by user";
}

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Payment result notice");
builder.setMessage(msg);
builder.setInverseBackgroundForced(true);
// builder.setCustomTitle();
builder.setNegativeButton("Determine", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}

Obfuscated code

    -keep class org.simalliance.openmobileapi.** {*;}
-keep class org.simalliance.openmobileapi.service.** {*;}

-keep class com.unionpay.** {*;}

Please add group if you have any questions: 142739277

Posted by Craig_H on Sun, 08 Dec 2019 09:19:35 -0800