增加支付代码

This commit is contained in:
zhl 2020-11-19 15:50:46 +08:00
parent 9c6a55f164
commit 373483e52c
3 changed files with 38 additions and 8 deletions

View File

@ -6,6 +6,7 @@ import android.util.Log;
import com.hnjc.wjtx.vivo.VivoUnionHelper;
import com.vivo.unionsdk.open.MissOrderEventHandler;
import com.vivo.unionsdk.open.OrderResultInfo;
import com.vivo.unionsdk.open.VivoUnionSDK;
import java.util.ArrayList;
import java.util.List;
@ -16,7 +17,8 @@ public class JCApplication extends Application {
public void onCreate() {
super.onCreate();
Log.i("JCApplication", "JCApplication onCreate");
VivoUnionHelper.initSdk(this, true);
String appId = this.getString(R.string.app_id);
VivoUnionSDK.initSdk(this, appId, true);
/**
* 掉单注册接口 需要接入掉单补单处理的一定要加

View File

@ -27,6 +27,7 @@ import com.vivo.unionsdk.open.VivoAccountCallback;
import com.vivo.unionsdk.open.VivoConstants;
import com.vivo.unionsdk.open.VivoExitCallback;
import com.vivo.unionsdk.open.VivoPayCallback;
import com.vivo.unionsdk.open.VivoPayInfo;
import com.vivo.unionsdk.open.VivoRoleInfo;
import com.vivo.unionsdk.open.VivoUnionSDK;
@ -47,6 +48,7 @@ public class MainActivity extends Activity {
private String cpPayOrderNumber;
//订单金额
private String cpOrderAmount;
private String appId;
private final VivoAccountCallback mAcccountCallback = new VivoAccountCallback() {
@Override
@ -73,11 +75,12 @@ public class MainActivity extends Activity {
private VivoPayCallback mVivoPayCallback = new VivoPayCallback() {
// 客户端返回的支付结果不可靠请再查询服务器以服务器端最终的支付结果为准
@Override
public void onVivoPayResult(int i, OrderResultInfo orderResultInfo) {
public void onVivoPayResult(int code, OrderResultInfo orderResultInfo) {
Log.i(TAG, "onVivoPayResult: " + orderResultInfo.getTransNo());
Log.i(TAG, "CpOrderNumber: " + cpPayOrderNumber + " i = " + i);
if (i == VivoConstants.PAYMENT_RESULT_CODE_SUCCESS) {
Log.i(TAG, "CpOrderNumber: " + cpPayOrderNumber + " i = " + code);
String errmsg = "";
JSONObject obj = new JSONObject();
if (code == VivoConstants.PAYMENT_RESULT_CODE_SUCCESS) {
Toast.makeText(MainActivity.this, "支付成功", Toast.LENGTH_SHORT).show();
/**
* !!!! 一定要加否则无法通过上架审核 !!!
@ -86,13 +89,21 @@ public class MainActivity extends Activity {
*/
VivoUnionHelper.reportOrderComplete(orderResultInfo.getTransNo());
Log.i(TAG, "sendCompleteOrderNotification: " + orderResultInfo.getTransNo());
} else if (i == VivoConstants.PAYMENT_RESULT_CODE_CANCEL) {
} else if (code == VivoConstants.PAYMENT_RESULT_CODE_CANCEL) {
Toast.makeText(MainActivity.this, "取消支付", Toast.LENGTH_SHORT).show();
} else if (i == VivoConstants.PAYMENT_RESULT_CODE_UNKNOWN) {
} else if (code == VivoConstants.PAYMENT_RESULT_CODE_UNKNOWN) {
Toast.makeText(MainActivity.this, "未知状态,请查询订单", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "支付失败", Toast.LENGTH_SHORT).show();
}
try {
obj.put("errcode", code);
obj.put("errmsg", errmsg);
nativeAndroid.callExternalInterface("payResult", obj.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
};
@ -103,7 +114,7 @@ public class MainActivity extends Activity {
String preloadPath = AssetsUtil.getDiskFileDir(this, this.getString(R.string.preload_path));
String gameUrl = this.getString(R.string.game_url);
appId = this.getString(R.string.app_id);
nativeAndroid = new EgretNativeAndroid(this);
if (!nativeAndroid.checkGlEsVersion()) {
Toast.makeText(this, "This device does not support OpenGL ES 2.0.",
@ -272,7 +283,23 @@ public class MainActivity extends Activity {
String cpOrderId = jsonObject.getString("orderId");
String productCode = jsonObject.getString("productCode");
int count = jsonObject.getInt("count");
String money = jsonObject.getString("money"); // 未传
String notifyUrl = jsonObject.getString("notifyUrl"); // 未传
String productName = jsonObject.getString("productName"); // 未传
String productDesc = jsonObject.getString("productDesc"); //未传
String sign = jsonObject.getString("sign"); // 未传
//TODO: 平台的支付
VivoPayInfo vivoPayInfo = new VivoPayInfo.Builder()
.setAppId(appId)
.setCpOrderNo(cpOrderId)
.setNotifyUrl(notifyUrl)
.setOrderAmount(money)
.setProductName(productName)
.setProductDesc(productDesc)
.setVivoSignature(sign)
.setExtUid(mUid)
.build();
VivoUnionHelper.payV2(this, vivoPayInfo, mVivoPayCallback);
} catch (JSONException e) {
e.printStackTrace();
} catch ( Exception e ) {

View File

@ -9,4 +9,5 @@
<string name="launch_version">获取游戏版本</string>
<string name="launch_download">正在更新游戏资源</string>
<string name="launch_unzip">正在解压游戏资源</string>
<string name="app_id">104485272</string>
</resources>