APP支付

Android接入要点说明

基于Activity上下文调用CMBApi

商户APP应基于Activity上下文对CMBApi进行调用,相关要点如下:

1、实现与CMBApi进行交互的Activity,并在AndroidManifest中配置入口,以作为招行APP回调访问的入口

2、创建CMBApi接口对象

3、通过CMBApi接口对象向招行APP发送请求

4、转发招行APP发送的Intent给CMBApi接口对象

5、处理结果响应

在AndroidManifest.xml中配置与CMBApi进行交互的Activity

<activity
     android:name=".XXXActivity"
     android:label="@string/app_name"
     android:exported="true"
     android:launchMode="singleTop">
 
     <intent-filter>
         <action android:name="android.intent.action.VIEW"/>
         <category android:name="android.intent.category.DEFAULT"/>
         <data android:scheme="sdksample"/>
     </intent-filter>
 </activity>

要点:

1. android:scheme由招行业务系统与商户之间协商配置

2. activity请配置为商户自己接受回调的activity

3. 接收scheme的activity必须在manifest文件中配置:

    <category android:name="android.intent.category.DEFAULT"/>

创建CMBApi接口对象

  @Override
    public void onCreate(Bundle savedInstanceState) {
	    …
	    CMBApiFactory.createCMBApi(this, APPID);
	    …
    }

销毁CMBApi接口对象

为了防止内存泄露问题,当CMBApi对象不再需要时,可以通过如下方法销毁该对象:

CMBApiFactory.destroyCMBAPI();

通过CMBApi接口对象向招行APP发送请求

 final CMBRequest request = new CMBRequest();

       request.mRequestData = requestData;
       request.mCMBJumpUrl = jumpUrl;
       request.mH5Url = h5Url;
       request.mMethod = method;

       cmbApi.sendReq(request);

要点:

1. sendReq(request)方法返回值为错误码,错误码定义:

    0:请求成功

    -2:请求参数有误

转发招行APP发送的Intent给CMBApi接口对象

商户APP需要在onCreate(), onNewIntent()以及onActivityResult方法里面显式调用handleIntent方法,否则将收不到最终的业务处理结果回调。

1、onCreate()

@Override
    public void onCreate(Bundle savedInstanceState) {
	    …
	    api.createCMBApi(this, APPID);
	    api.handleIntent(getIntent, this);
	    …
    }

2、onNewIntent()

@Override
   protected void onNewIntent(Intent intent) {
      super.onNewIntent(intent);
   
      setIntent(intent);
      api.handleIntent(intent, this);
   }

3、onActivityResult()

 @Override
   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      api.handleIntent(intent, this);
   }

处理结果响应

商户APP入口Activity应实现CMBEventHandler接口以接收业务结果响应:

public class CMBApiEntryActivity extends Activity implements
    CMBApi.CMBEventHandler {
        @Override
        public void onResp(CMBResponse resp) {
        if (0 == resp.mRespCode){
            //handle result in resp.mRespMsg
        }
        else {
           //handle errorCode in resp.mRespCode
           //handle error in resp.mRespMsg
        }
    }

要点:

1. 在类实现onResp函数,请求完成(如支付)后,招商银行APP会返回到商户APP并回调onResp函数,开发者需要在该函数中接收通知,判断返回错误码,如果请求(如支付)处理成功则去后台查询请求结果再展示用户实际结果。

2. 一定不能以客户端的回调结果作为展示给用户的结果,应以服务器端的接收的请求(如支付)处理通知或查询API返回的结果为准

自定义H5页面回调接收

商户在自定义H5支付页面中,通过CMBWebViewListener接口的onClosed(int respCode, String respString)方法来监听用户页面内关闭操作。通过onTitleChanged(String title)方法来监听支付页面标题变化。