react-native 接QQ钱包支付的SDK
目前没有npm安装,需要自行引入第三方sdk
因业务需求需要接QQ钱包支付,网上也没有相应的教程、步骤。只好自己摸索,在这里写下我的解决方案给需要用到的人,更快的接好QQ钱包支付,也给自己记下笔记(目前接触react-native才1个月多不是很深入了解其原理,只停留在实现业务功能的层面,解决方案不是很到位)
配置步骤
android (ios 要走内购流程IAP)
1.去QQ钱包商户平台下载需要的SDK把下载好的 mqqopenpay.jar 放在 android>app>libs 目录下
2.在android>app>src>main>java>cn>test下创建qqwallet文件夹(cn>test为你的包名具体按各自的目录名字来)里面分别放三个文件(拷贝即可)
- CallbackActivity.java (处理支付回调)
- QqWalletModule.java (编写react-native可以使用的方法)
- QqWalletPackage.java (连接android跟react-native)
CallbackAcvity.java
package cn.test.qqwallet; // test改成你项目中的包名
import com.tencent.mobileqq.openpay.api.IOpenApi;
import com.tencent.mobileqq.openpay.api.IOpenApiListener;
import com.tencent.mobileqq.openpay.api.OpenApiFactory;
import com.tencent.mobileqq.openpay.data.base.BaseResponse;
import com.tencent.mobileqq.openpay.data.pay.PayResponse;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import com.facebook.react.bridge.ReadableMap;
public class CallbackActivity extends Activity implements IOpenApiListener {
IOpenApi openApi;
// 处理支付回调
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
openApi = OpenApiFactory.getInstance(this, QqWalletModule.APP_ID);
openApi.handleIntent(getIntent(), this);
}
// 处理支付回调
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
openApi.handleIntent(intent, this);
}
// 返回支付结果
@Override
public void onOpenResponse(BaseResponse response) {
String message;
if (response == null) {
message = null;
return;
} else {
if (response instanceof PayResponse) {
PayResponse payResponse = (PayResponse) response;
message = "{\"apiName\":\"" + payResponse.apiName + "\","
+ "\"serialnumber\":\"" + payResponse.serialNumber + "\","
+ "\"isSucess\":" + payResponse.isSuccess() + ","
+ "\"retCode\":" + payResponse.retCode + ","
+ "\"retMsg\":\"" + payResponse.retMsg + "\"";
message += "}";
} else {
message = "notPayResponse";
}
}
QqWalletModule.promise.resolve