增加登陆和支付回调的示例代码

This commit is contained in:
zhl 2020-11-19 19:09:03 +08:00
parent 36e83cdd26
commit e29648f328

View File

@ -17,6 +17,7 @@ import android.widget.ImageView;
import android.widget.Toast;
import com.hnjc.wjtx.util.AssetsUtil;
import com.hnjc.wjtx.util.IdUtil;
import com.hnjc.wjtx.util.StorageUtil;
import com.hnjc.wjtx.util.StringUtil;
@ -163,6 +164,18 @@ public class MainActivity extends Activity {
});
nativeAndroid.setExternalInterface("getUid", message -> {
//TODO: 平台的登陆
JSONObject obj = new JSONObject();
try {
obj.put("openid", IdUtil.getUid(this));
obj.put("token", "");
// 如果其他登陆过程中的错误, 则传入一个大于0的errorcode
obj.put("errorcode", 1);
nativeAndroid.callExternalInterface("sendUidToJS", obj.toString());
} catch (JSONException e) {
e.printStackTrace();
nativeAndroid.callExternalInterface("loginCancel", "");
}
});
nativeAndroid.setExternalInterface("@onState", message -> {
Log.e(TAG, "Get @onState: " + message);
@ -186,6 +199,14 @@ public class MainActivity extends Activity {
String productCode = jsonObject.getString("productCode");
int count = jsonObject.getInt("count");
//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) {
e.printStackTrace();
} catch ( Exception e ) {