调通百度支付
This commit is contained in:
parent
e11ccb2fb4
commit
0c6d26b3d0
@ -15,13 +15,13 @@ public class BaseActivity extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
BDGameSDK.onResume(this); // todo:【必接】Activity监听
|
BDGameSDK.onResume(this); // 【必接】Activity监听
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
BDGameSDK.onPause(this); // todo:【必接】Activity监听
|
BDGameSDK.onPause(this); // 【必接】Activity监听
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -183,58 +183,47 @@ public class MainActivity extends BaseActivity {
|
|||||||
Log.i(TAG, "begin pay: " + message);
|
Log.i(TAG, "begin pay: " + message);
|
||||||
try {
|
try {
|
||||||
JSONObject jsonObject = new JSONObject(message);
|
JSONObject jsonObject = new JSONObject(message);
|
||||||
String cpOrderId = jsonObject.getString("orderId");
|
|
||||||
String productCode = jsonObject.getString("productCode");
|
|
||||||
int count = jsonObject.getInt("count");
|
|
||||||
|
|
||||||
PayOrderInfo payOrderInfo = new PayOrderInfo();
|
PayOrderInfo payOrderInfo = new PayOrderInfo();
|
||||||
payOrderInfo.setCooperatorOrderSerial(cpOrderId);
|
payOrderInfo.setCooperatorOrderSerial(jsonObject.getString("cooperatorOrderSerial"));
|
||||||
// payOrderInfo.setProductName(goodsName);
|
payOrderInfo.setProductName(jsonObject.getString("productName"));
|
||||||
// long p = Long.parseLong(totalAmount);
|
payOrderInfo.setTotalPriceCent(jsonObject.getLong("totalPriceCent")); // 以分为单位
|
||||||
// payOrderInfo.setTotalPriceCent(p); // 以分为单位
|
payOrderInfo.setRatio(jsonObject.getInt("ratio"));
|
||||||
// payOrderInfo.setRatio(ratio);
|
payOrderInfo.setExtInfo(jsonObject.getString("extInfo")); // 该字段将会在支付成功后原样返回给CP(不超过500个字符)
|
||||||
// payOrderInfo.setExtInfo(extInfo); // 该字段将会在支付成功后原样返回给CP(不超过500个字符)
|
payOrderInfo.setCpUid(jsonObject.getString("uid")); // 必传字段,需要验证uid是否合法,此字段必须是登陆后或者切换账号后保存的uid
|
||||||
// payOrderInfo.setCpUid(BDGameSDK.getLoginUid()); // 必传字段,需要验证uid是否合法,此字段必须是登陆后或者切换账号后保存的uid
|
|
||||||
// if (isPayToBaidu) {
|
// if (isPayToBaidu) {
|
||||||
// payOrderInfo.isPurchaseBaiduGoods = "true";
|
// payOrderInfo.isPurchaseBaiduGoods = "true";
|
||||||
// }
|
// }
|
||||||
|
|
||||||
BDGameSDK.pay(MainActivity.this, payOrderInfo, null,
|
BDGameSDK.pay(MainActivity.this, payOrderInfo, null,
|
||||||
(resultCode, resultDesc, extraData) -> {
|
(resultCode, resultDesc, extraData) -> {
|
||||||
// alertDialog.cancel();
|
// alertDialog.cancel();
|
||||||
String resultStr = "";
|
JSONObject obj = new JSONObject();
|
||||||
switch (resultCode) {
|
try {
|
||||||
case ResultCode.PAY_SUCCESS: // 支付成功
|
obj.put("errcode", resultCode);
|
||||||
resultStr = "支付成功:" + resultDesc;
|
String resultStr = "";
|
||||||
break;
|
switch (resultCode) {
|
||||||
case ResultCode.PAY_CANCEL: // 订单支付取消
|
case ResultCode.PAY_SUCCESS: // 支付成功
|
||||||
resultStr = "取消支付";
|
resultStr = "支付成功:" + resultDesc;
|
||||||
break;
|
break;
|
||||||
case ResultCode.PAY_FAIL: // 订单支付失败
|
case ResultCode.PAY_CANCEL: // 订单支付取消
|
||||||
resultStr = "支付失败:" + resultDesc;
|
resultStr = "取消支付";
|
||||||
break;
|
break;
|
||||||
case ResultCode.PAY_SUBMIT_ORDER: // 订单已经提交,支付结果未知(比如:已经请求了,但是查询超时)
|
case ResultCode.PAY_FAIL: // 订单支付失败
|
||||||
resultStr = "订单已经提交,支付结果未知";
|
resultStr = "支付失败:" + resultDesc;
|
||||||
break;
|
break;
|
||||||
default:
|
case ResultCode.PAY_SUBMIT_ORDER: // 订单已经提交,支付结果未知(比如:已经请求了,但是查询超时)
|
||||||
resultStr = "订单已经提交,支付结果未知";
|
resultStr = "订单已经提交,支付结果未知";
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
resultStr = "订单已经提交,支付结果未知";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
obj.put("errmsg", resultStr);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
Toast.makeText(getApplicationContext(), resultStr,
|
nativeAndroid.callExternalInterface("payResult", obj.toString());
|
||||||
Toast.LENGTH_LONG).show();
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//TODO: 平台的支付
|
|
||||||
JSONObject obj = new JSONObject();
|
|
||||||
try {
|
|
||||||
obj.put("errcode", 0);
|
|
||||||
obj.put("errmsg", "");
|
|
||||||
nativeAndroid.callExternalInterface("payResult", obj.toString());
|
|
||||||
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
@ -258,28 +247,29 @@ public class MainActivity extends BaseActivity {
|
|||||||
*/
|
*/
|
||||||
nativeAndroid.setExternalInterface("reportRoleInfo", message -> {
|
nativeAndroid.setExternalInterface("reportRoleInfo", message -> {
|
||||||
Log.i(TAG, "Get reportRoleInfo: " + message);
|
Log.i(TAG, "Get reportRoleInfo: " + message);
|
||||||
|
//TODO:
|
||||||
|
// 上报玩家游戏角色信息Json串,格式为:{
|
||||||
|
// "nick":"昵称",
|
||||||
|
// "role":"角色名",
|
||||||
|
// "region":"(游戏)大区",
|
||||||
|
// "server":"(游戏)服",
|
||||||
|
// "level":"角色等级",
|
||||||
|
// "power":"玩家战力值"
|
||||||
|
// }
|
||||||
|
JSONObject data = new JSONObject();
|
||||||
|
try {
|
||||||
|
JSONObject obj = new JSONObject(message);
|
||||||
|
data.put("nick", obj.getString("userRoleName"));
|
||||||
|
data.put("role", "1");
|
||||||
|
data.put("region", obj.getString("serverName"));
|
||||||
|
data.put("server", obj.getString("serverId"));
|
||||||
|
data.put("level", obj.getInt("userRoleLevel"));
|
||||||
|
data.put("power", obj.getString("gameRolePower"));
|
||||||
|
BDGameSDK.reportUserData(data.toString());
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
//TODO:
|
|
||||||
// 上报玩家游戏角色信息Json串,格式为:{
|
|
||||||
// "nick":"昵称",
|
|
||||||
// "role":"角色名",
|
|
||||||
// "region":"(游戏)大区",
|
|
||||||
// "server":"(游戏)服",
|
|
||||||
// "level":"角色等级",
|
|
||||||
// "power":"玩家战力值"
|
|
||||||
// }
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
try {
|
|
||||||
data.put("nick", "齐天大圣");
|
|
||||||
data.put("role", "战士");
|
|
||||||
data.put("region", "中国");
|
|
||||||
data.put("server", "001");
|
|
||||||
data.put("level", 88);
|
|
||||||
data.put("power", 99999);
|
|
||||||
BDGameSDK.reportUserData(data.toString());
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -336,8 +326,7 @@ public class MainActivity extends BaseActivity {
|
|||||||
case ResultCode.LOGIN_FAIL:
|
case ResultCode.LOGIN_FAIL:
|
||||||
// TODO
|
// TODO
|
||||||
// 登录失败,游戏内部之前如果是已经登录的,要清除自己记录的登录状态,设置成未登录。如果之前未登录,不用处理。
|
// 登录失败,游戏内部之前如果是已经登录的,要清除自己记录的登录状态,设置成未登录。如果之前未登录,不用处理。
|
||||||
Toast.makeText(getApplicationContext(), "登录失败",
|
Toast.makeText(getApplicationContext(), "登录失败", Toast.LENGTH_LONG).show();
|
||||||
Toast.LENGTH_LONG).show();
|
|
||||||
break;
|
break;
|
||||||
case ResultCode.LOGIN_CANCEL:
|
case ResultCode.LOGIN_CANCEL:
|
||||||
// TODO 取消,操作前后的登录状态没变化
|
// TODO 取消,操作前后的登录状态没变化
|
||||||
|
Loading…
x
Reference in New Issue
Block a user