@Override
    public void onConnect(int rst, HuaweiApiClient client) {

        HMSAgentLog.d("onConnect:" + rst);

        if (client == null || !ApiClientMgr.INST.isConnect(client)) {
            HMSAgentLog.e("client not connted");
            onPMSPayEnd(rst, null);
            return;
        }

        // 调用HMS-SDK pay 接口
        PendingResult<PayResult> payResult = HuaweiPay.HuaweiPayApi.productPay(client, payReq);
        payResult.setResultCallback(new ResultCallback<PayResult>() {
            @Override
            public void onResult(PayResult result) {

                if (result == null) {
                    HMSAgentLog.e("result is null");
                    onPMSPayEnd(HMSAgent.AgentResultCode.RESULT_IS_NULL, null);
                    return;
                }

                Status status = result.getStatus();
                if (status == null) {
                    HMSAgentLog.e("status is null");
                    onPMSPayEnd(HMSAgent.AgentResultCode.STATUS_IS_NULL, null);
                    return;
                }

                int rstCode = status.getStatusCode();
                HMSAgentLog.d("status=" + status);
                // 需要重试的错误码，并且可以重试
                if ((rstCode == CommonCode.ErrorCode.SESSION_INVALID
                        || rstCode == CommonCode.ErrorCode.CLIENT_API_INVALID) && retryTimes > 0) {
                    retryTimes--;
                    connect();
                } else if (rstCode == PayStatusCodes.PAY_STATE_SUCCESS) {
                    // 支付校验完成，取当前activity进行后续支付操作
                    Activity curActivity = ActivityMgr.INST.getLastActivity();
                    if (curActivity == null) {
                        HMSAgentLog.e("activity is null");
                        onPMSPayEnd(HMSAgent.AgentResultCode.NO_ACTIVITY_FOR_USE, null);
                        return;
                    }

                    if (statusForPay != null) {
                        HMSAgentLog.e("has already a pay to dispose");
                        onPMSPayEnd(HMSAgent.AgentResultCode.REQUEST_REPEATED, null);
                        return;
                    }

                    //启动支付流程
                    try {
                        statusForPay = status;
                        Intent intent = new Intent(curActivity, HMSPMSPayAgentActivity.class);
                        intent.putExtra(BaseAgentActivity.EXTRA_IS_FULLSCREEN, UIUtils.isActivityFullscreen(curActivity));
                        curActivity.startActivity(intent);
                    } catch (Exception e) {
                        HMSAgentLog.e("start HMSPayAgentActivity error:" + e.getMessage());
                        onPMSPayEnd(HMSAgent.AgentResultCode.START_ACTIVITY_ERROR, null);
                    }
                }else {
                    onPMSPayEnd(rstCode, null);
                }
            }
        });
    }
@ Override public void onConnect ( int rst , HuaweiApiClient client ) { HMSAgentLog . d ( "onConnect:" + rst ) ; if ( client == null || ! ApiClientMgr . INST . isConnect ( client ) ) { HMSAgentLog . e ( "client not connted" ) ; onPMSPayEnd ( rst , null ) ; return ; } PendingResult < PayResult > payResult = HuaweiPay . HuaweiPayApi . productPay ( client , payReq ) ; payResult . setResultCallback ( new ResultCallback < PayResult > ( ) { @ Override public void onResult ( PayResult result ) { if ( result == null ) { HMSAgentLog . e ( "result is null" ) ; onPMSPayEnd ( HMSAgent . AgentResultCode . RESULT_IS_NULL , null ) ; return ; } Status status = result . getStatus ( ) ; if ( status == null ) { HMSAgentLog . e ( "status is null" ) ; onPMSPayEnd ( HMSAgent . AgentResultCode . STATUS_IS_NULL , null ) ; return ; } int rstCode = status . getStatusCode ( ) ; HMSAgentLog . d ( "status=" + status ) ; if ( ( rstCode == CommonCode . ErrorCode . SESSION_INVALID || rstCode == CommonCode . ErrorCode . CLIENT_API_INVALID ) && retryTimes > 0 ) { retryTimes -- ; connect ( ) ; } else if ( rstCode == PayStatusCodes . PAY_STATE_SUCCESS ) { Activity curActivity = ActivityMgr . INST . getLastActivity ( ) ; if ( curActivity == null ) { HMSAgentLog . e ( "activity is null" ) ; onPMSPayEnd ( HMSAgent . AgentResultCode . NO_ACTIVITY_FOR_USE , null ) ; return ; } if ( statusForPay != null ) { HMSAgentLog . e ( "has already a pay to dispose" ) ; onPMSPayEnd ( HMSAgent . AgentResultCode . REQUEST_REPEATED , null ) ; return ; } try { statusForPay = status ; Intent intent = new Intent ( curActivity , HMSPMSPayAgentActivity . class ) ; intent . putExtra ( BaseAgentActivity . EXTRA_IS_FULLSCREEN , UIUtils . isActivityFullscreen ( curActivity ) ) ; curActivity . startActivity ( intent ) ; } catch ( Exception e ) { HMSAgentLog . e ( "start HMSPayAgentActivity error:" + e . getMessage ( ) ) ; onPMSPayEnd ( HMSAgent . AgentResultCode . START_ACTIVITY_ERROR , null ) ; } } else { onPMSPayEnd ( rstCode , null ) ; } } } ) ; }
Huawei Api Client 连接回调
@param rst 结果码
@param client HuaweiApiClient 实例