//加载并显示二维码图片
public void beginShowUserSwitchErcode(){
DySdkLog.Log("beginShowUserSwitchErcode LjDySdk.beginUserSwitch1");
LjDySdk.beginUserSwitch1(myBehaviour, new ErCodeKeyCommonNotify(myBehaviour, targetRawImage));
}
//如果本身不用知道结果,则直接传 new CommonApiNotify()
class ErCodeKeyCommonNotify : CommonApiNotify
{
private MonoBehaviour mBehaviour;
private RawImage mRawImage;
public ErCodeKeyCommonNotify(MonoBehaviour behaviour, RawImage rawImage)
{
mBehaviour = behaviour;
mRawImage = rawImage;
if (mRawImage!=null)
{
DySdkLog.Log("mRawImage is not null");
}
}
public override void notifySuccess(string str)
{
base.notifySuccess(str);
DySdkLog.Log("ErCodeKeyCommonNotify notifySuccess=" + str);
if(str!=null&&!"".Equals(str)){
try
{
JsonData jsonData2 = JsonMapper.ToObject(str);
if(((IDictionary)jsonData2).Contains("data")){
JsonData jsonData4=jsonData2["data"];
string key = jsonData4["key"].ToString();
if(key!=null&&!"".Equals(key)){
sErCodeKey=key;
string picUrl = LjDySdk.sTagUserSwitch2+key;
DySdkLog.Log("ErCodeKeyCommonNotify key picurl= " + picUrl);
LoadErCodePic util=new LoadErCodePic();
util.beginLoadAndShowPic(mBehaviour, picUrl, mRawImage);
beginTimerRefresh(mBehaviour, sErCodeKey, mRawImage);
}
}
}
catch (SystemException e1)
{
DySdkLog.LogError(e1.ToString());
}
}
}
}
private static void beginTimerRefresh(MonoBehaviour behaviour, string key, RawImage rawImage){
// 延迟4秒执行一次
DySdkLog.Log("beginTimerRefresh");
TimerManager.Instance.Delay(4f, () => {
DySdkLog.Log("抖音小程序原生定时器:延迟4秒执行");
LjDySdk.beginUserSwitch5(behaviour, key, new MyTimerNotify(behaviour, key, rawImage));
});
}
class MyTimerNotify : CommonApiNotify
{
private MonoBehaviour mBehaviour;
private string mKey;
private RawImage mRawImage;
public MyTimerNotify(MonoBehaviour behaviour, string key, RawImage rawImage){
mBehaviour = behaviour;
mKey=key;
mRawImage=rawImage;
}
public override void notifyComplete(string str, bool success)
{
base.notifyComplete(str, success);
DySdkLog.Log("MyTimerNotify notifyComplete = " + str + " , success = " + success);
bool reloadData=true;
if(str!=null && !"".Equals(str)){
try {
if(success){
JsonData jsonData2 = JsonMapper.ToObject(str);
if(((IDictionary)jsonData2).Contains("code")){
string code=jsonData2["code"].ToString();
bool showExpireTimeDlg=false;
if("1".Equals(code)){
reloadData=false;
showExpireTimeDlg=true;
}else if("0".Equals(code)){
if(((IDictionary)jsonData2).Contains("data")){
JsonData jsonData4=jsonData2["data"];
string status = jsonData4["status"].ToString();
// 0等待扫码 1等待确认 2已确认 4已失效
if("4".Equals(status)){
reloadData = false;
showExpireTimeDlg=true;
}else if("2".Equals(status)){
LjDySdk.sSwitchUserFlag=true;
reloadData = false;
string auth_open_id = jsonData4["auth_open_id"].ToString();//授权后的切换的 userId
DySdkLog.Log("MyTimerNotify notifyComplete auth_open_id " + auth_open_id);
//设置 openid
LjDySdk.sMemOpenId = auth_open_id;
PlayerPrefs.SetString(LjDySdk.LJSDK_GNAME + LoginApiNotify.tag_openid , auth_open_id);
//设置 unionid
LjDySdk.sMemUnionId = "";
PlayerPrefs.SetString(LjDySdk.LJSDK_GNAME + LoginApiNotify.tag_unionid, "");
//吐司提醒切换成功
StarkUIManager.ShowToast("账号切换成功!");
}
}
}
if(showExpireTimeDlg){
mRawImage.texture = null;
ConfirmDialog.instance.Show("the pic expired time ,are you sure reload ercode pic?", "Confirm", () => {
DySdkLog.Log("click ok button");
//开始重新加载图片
LjDySdk.beginUserSwitch1(mBehaviour, new ErCodeKeyCommonNotify(mBehaviour, mRawImage));
});
}
}
}
} catch (SystemException e1) {
DySdkLog.Log("MyTimerNotify errorinfo1=" + e1.ToString());
} catch (JsonException e1) {
DySdkLog.Log("MyTimerNotify errorinfo2=" + e1.ToString());
}
}
if(reloadData){
beginTimerRefresh(mBehaviour, mKey, mRawImage);
}
}
}
public void beginSwitchScanInfo(){
DySdkLog.Log("click beginSwitchScanInfo");
//已经有验证登录信息和返回扫描结果,后面的确认框由研发自己修改调试
LjDySdk.beginScanCode(myBehaviour, new ScanResult1CommonNotify(myBehaviour));
}
class ScanResult1CommonNotify : CommonApiNotify
{
private MonoBehaviour mBehaviour;
public ScanResult1CommonNotify(MonoBehaviour behaviour){
mBehaviour=behaviour;
}
public override void notifySuccess(string str)
{
base.notifySuccess(str);
DySdkLog.Log("ScanResult1CommonNotify notifySuccess=" + str);
LjDySdk.beginUserSwitch3(mBehaviour, str, new ScanResult2CommonNotify(mBehaviour, str));
}
}
//立马验证code是否已经过期
class ScanResult2CommonNotify : CommonApiNotify
{
private MonoBehaviour mBehaviour;
private string mKey;
public ScanResult2CommonNotify(MonoBehaviour behaviour, string key){
mBehaviour=behaviour;
mKey=key;
}
public override void notifySuccess(string str)
{
base.notifySuccess(str);
DySdkLog.Log("ScanResult2CommonNotify notifySuccess=" + str);
JsonData jsonData2 = JsonMapper.ToObject(str);
if(((IDictionary)jsonData2).Contains("code")){
string code=jsonData2["code"].ToString();
string tip6="";
if("1".Equals(code)){
tip6="二维码已过期,请获取最新二维码!";
StarkUIManager.ShowToast(tip6);
DySdkLog.Log(tip6);
}else if("0".Equals(code)){
ConfirmDialog.instance.Show("are you sure confirm login on other device?", "Confirm", () => {
DySdkLog.Log("click ok button");
// str="928a6df05e5324d2db5cd117ee7482ca";
LjDySdk.beginUserSwitch4(mBehaviour, mKey, new ScanResult3CommonNotify(mBehaviour, mKey));
});
}
}
}
}
// 用户点击确认对话框后立马切换账号逻辑
class ScanResult3CommonNotify : CommonApiNotify
{
private MonoBehaviour mBehaviour;
private string mKey;
public ScanResult3CommonNotify(MonoBehaviour behaviour, string key){
mBehaviour=behaviour;
mKey=key;
}
public override void notifySuccess(string str)
{
base.notifySuccess(str);
DySdkLog.Log("MyCommonNotify notifySuccess=" + str);
JsonData jsonData2 = JsonMapper.ToObject(str);
if(((IDictionary)jsonData2).Contains("code")){
string code=jsonData2["code"].ToString();
string tip6="";
if("1".Equals(code)){
tip6="二维码已过期,请获取最新二维码重新扫码!";
StarkUIManager.ShowToast(tip6);
DySdkLog.Log(tip6);
}else if("0".Equals(code)){
tip6="授权已成功!";
StarkUIManager.ShowToast(tip6);
DySdkLog.Log(tip6);
}
}
}
}