支付宝支付集成

  • 代码

public void getAliOrderInfo(String money) {

String url = Contacts.SHAir_SERVICE + Contacts.ServiceConstant.CACHE_PAY;
HashMap params = new HashMap<>();
params.put("", "");
params.put("", );

//通过后台给的接口请求数据
OkGo.post(url).tag(getContext())
        .params(params, false)
        .execute(new StringCallback() {
            @Override
            public void onSuccess(String s, Call call, Response response) {

                try {
                    AliPay_bean aliPay_bean = new Gson().fromJson(s, AliPay_bean.class);
                    if (aliPay_bean.getCode().equals("1")) {
                        final String orderInfo = aliPay_bean.getData();

                        Runnable payRunnable = new Runnable() {

                            @Override
                            public void run() {
                                PayTask alipayTask = new PayTask(activity);
                                Map result = alipayTask.payV2(orderInfo, true);

                                Message msg = new Message();
                                msg.what = SDK_PAY_FLAG;
                                msg.obj = result;
                                mHandler.sendMessage(msg);

                            }
                        };
                        // 必须异步调用
                        Thread payThread = new Thread(payRunnable);
                        payThread.start();
                    } else{
                        ToastUtil.showToastShort(getContext(), "调用失败");
                    } 
                } catch (Exception e) {
                    e.printStackTrace();
                    Log.e("Fragment_Cost_imme", e.toString());
                    ToastUtil.showToastShort(getContext(), "请求异常");
                }

            }
        });

}

private Handler mHandler = new Handler() {
@SuppressWarnings("unused")
public void handleMessage(Message msg) {
switch (msg.what) {
case SDK_PAY_FLAG: {
PayResult payResult = new PayResult((Map) msg.obj);

            //同步通知支付结果。
            String resultInfo = payResult.getResult();
            String resultStatus = payResult.getResultStatus();

            // 判断resultStatus 为9000则代表支付成功
            if (TextUtils.equals(resultStatus, "9000")) {
                Toast.makeText(getContext(), "支付成功", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getContext(), "支付失败", Toast.LENGTH_SHORT).show();
            }
            break;
        }

    }
}

};

  • 混淆

-libraryjars libs/alipaySDK-20150602.jar

-keep class com.alipay.android.app.IAlixPay{;}
-keep class com.alipay.android.app.IAlixPay$Stub{
;}
-keep class com.alipay.android.app.IRemoteServiceCallback{;}
-keep class com.alipay.android.app.IRemoteServiceCallback$Stub{
;}
-keep class com.alipay.sdk.app.PayTask{ public *;}
-keep class com.alipay.sdk.app.AuthTask{ public *;}

  • 配置

android:name="com.alipay.sdk.app.H5PayActivity"
android:configChanges="orientation|keyboardHidden|navigation"
android:exported="false"
android:screenOrientation="behind">

android:name="com.alipay.sdk.auth.AuthActivity"
android:configChanges="orientation|keyboardHidden|navigation"
android:exported="false"
android:screenOrientation="behind">

  • 权限





  • gradle

compile files('libs/alipaySingle-20170510.jar')

你可能感兴趣的:(支付宝支付集成)