﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
using MiaoJuWxSDK.Singleton;
using LitJson;

namespace MiaoJuWxSDK
{
    public class MiaoJuWxSDKBridge : MIAOJUSingletonMonoBehaviour<MiaoJuWxSDKBridge>
    {
        private bool isDemoDebug = false;
#if !UNITY_EDITOR && UNITY_WEBGL
        [DllImport("__Internal")]
        private static extern void isDebug(string isdebug);
        [DllImport("__Internal")]
        private static extern void init(string initParams);
        [DllImport("__Internal")]
        private static extern void pay(string payParams);

        [DllImport("__Internal")]
        private static extern void share(string shareParams);
        [DllImport("__Internal")]
        private static extern void shareOpen(string shareOpenParams);
        [DllImport("__Internal")]
        private static extern void openCustomerService(string openCustomerParams);
        [DllImport("__Internal")]
        private static extern void getUserInfo(string initParams);
        [DllImport("__Internal")]
        private static extern void createUserInfoButton(string initParams);
        [DllImport("__Internal")]
        private static extern void createRole(string initParams);
        [DllImport("__Internal")]
        private static extern void changeRole(string initParams);
        [DllImport("__Internal")]
        private static extern void loginRole(string loginRoleParams);
        [DllImport("__Internal")]
        private static extern void reportLog(string reportLogParams);
        [DllImport("__Internal")]
        private static extern void rewardVideoAdCreate(string reportLogParams);
        [DllImport("__Internal")]
        private static extern void buttonOne(string paramsOne);
        [DllImport("__Internal")]
        private static extern void buttonTwo(string paramsTwo);

        [DllImport("__Internal")]
        private static extern void ssUserSet(string ssUserSetParams);
        [DllImport("__Internal")]
        private static extern void ssReport(string ssReportParams);
        [DllImport("__Internal")]
        private static extern void ylyqReport(string ylyqReportParams);
        [DllImport("__Internal")]
        private static extern string getUserLaunchInfo();
        [DllImport("__Internal")]
        private static extern string destoryUserInfoButton(string destroyButton);
        [DllImport("__Internal")]
        private static extern string joinVoIPChat(string contentText);
        [DllImport("__Internal")]
        private static extern string exitVoIPChat(string contentText);
        [DllImport("__Internal")]
        private static extern string updateVoIPChatMuteConfig(string contentText);
        [DllImport("__Internal")]
        private static extern string requestSubscribeMessage(string contentText);
        [DllImport("__Internal")]
        private static extern string requestSubscribeSystemMessage(string contentText);
        [DllImport("__Internal")]
        private static extern string checkIsAddedToMyMiniProgram(string contentText);
        [DllImport("__Internal")]
        private static extern string rewardVideoAdCreate2(string contentText);
        [DllImport("__Internal")]
        private static extern string getLocation(string contentText);
        [DllImport("__Internal")]
        private static extern string getSetting(string contentText);
#endif


        public new void Awake()
        {
#if UNITY_EDITOR
            return;
#endif
        }

        #region --------------调用js方法---------------------
        /*
         * 设置是否debug模式 是否打印日志
         * param bool:true 打印日志 false:不打印日志
         * return 
         */
        public void IsDebug(bool isDebugSet)
        {
            isDemoDebug = isDebugSet;
#if !UNITY_EDITOR && UNITY_WEBGL
            if (isDebugSet)
            {
                isDebug("1");
            }
            else
            {
                isDebug("0");
            }
#endif

        }

        /*
         * 调用js 初始化
         * param 
         * return void
         */
        [System.Serializable]
        public class InitData
        {
            public int gameId;
            public string ssAppId;//数数App ID
            public string gameVersion;
            public string ylyqAccessToken;//引力引擎Access Token
            public object envConfig;//环境配置，production正式，test测试
        }
        public enum EnvConfig
        {
            production,
            test
        }

        private string ObjectParamToString(object paramObject)
        {
            string jsonStr = "";
            try
            {
                if (paramObject is null)
                {
                    return "";
                }
                if (paramObject.GetType() == typeof(string))
                {
                    return paramObject as string;
                }
                jsonStr = JsonMapper.ToJson(paramObject);
            }
            catch (Exception ex)
            {
                Debug.Log("ObjectParamToString error:" + ex.Message);
            }
            Debug.Log("u8：" + jsonStr);
            return jsonStr;
        }

        public void CopeTextContent(string copeText)
        {
        #if UNITY_EDITOR
            GUIUtility.systemCopyBuffer = copeText;
            return;
        #elif UNITY_WEBGL
        #endif
        }

        /*
         * 初始化
         * @param initData:object   callBack:InitCallBack//回调方法 非必传
         * @return void 
         */
        public delegate void InitCallBack(string result);
        public InitCallBack initCallBack = null;
        public void Init(object initData, InitCallBack callBack = null)
        {
            Debug.Log("init UNITY_WEBGL fun before:");
            string initParam = ObjectParamToString(initData);
            Debug.Log("init UNITY_WEBGL fun after:");
            initCallBack = callBack;
#if UNITY_EDITOR
            Debug.Log("init func");
            return;
#elif UNITY_WEBGL
            Debug.Log("init UNITY_WEBGL fun:"+initParam);
            init(initParam);
#endif
        }

        /*
         * 调用js 初始化->js回调
         * param 
         * return void
         */
        public void InitCallBackFromJs(string result)
        {
            initCallBack?.Invoke(result);
        }


        
        /*
         * 获取启动参数
         */
        public string GetUserLaunchInfo()
        {
#if UNITY_EDITOR
            DemoDebugLog("GetUserLaunchInfo info");
            return "{\"code\":1000,\"message\":\"success\",\"data\":{}}";
#elif UNITY_WEBGL
            string info = getUserLaunchInfo();
            return info;
#else
            return"";
#endif
        }

        /*
        * 调用js 支付
        * param 
        * return void
        */
        [System.Serializable]
        public class PayData
        {
            public string productId;
            public string gameOrderId;//游戏订单ID
            public string serverId;//服ID
            public string serverName;//服名
            public string roleId;////角色ID
            public string roleName;//角色名
            public string roleLevel;//角色等级
            public int buyQuantity;//购买数量
            public int goodsPrice;//单价分
            public string payNoticeUrl;//支付回调服务端地址
            public object customData;
            public object conversationParams;
        }
        public delegate void PayCallBack(string result);
        public PayCallBack payCallBack = null;

        public void Pay(object param, PayCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);

            payCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog(paramStr);
            DemoDebugLog("pay func");
            return;
#elif UNITY_WEBGL
            pay(paramStr);
#endif
        }

        public void PayCallBackFromJs(string result)
        {
            DemoDebugLog("PayCallBackFromJs:" + result);
            payCallBack?.Invoke(result);
        }

        /*
        * 调用js 激励广告
        * param 
        * return void
        */
        [System.Serializable]
        public class RewardVideoAdCreateData
        {
            public string adUnitId;
        }
        public delegate void RewardVideoAdCallBack(string result);//JSCALLBACKDATA<Dictionary<string, object>> result
        public RewardVideoAdCallBack rewardVideoAdCallBack = null;


        public void RewardVideoAdCreate(object param, RewardVideoAdCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            rewardVideoAdCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("RewardVideoAdCreate func");
            DemoDebugLog(paramStr);
            return;
#elif UNITY_WEBGL
            rewardVideoAdCreate(paramStr);
#endif
        }


        public void RewardVideoAdCreateCallBackFromJs(string result)
        {
            DemoDebugLog("RewardVideoAdCallBackFromJs:" + result);
            rewardVideoAdCallBack?.Invoke(result);
        }



        /*
        * 调用js 分享
        * param 
        * return void
        */
        [System.Serializable]
        public class ShareData
        {
            public string title;//标题
            public string imageUrl;//转发显示图片的链接，可以是网络图片路径或本地图片文件路径或相对代码包根目录的图片文件路径
            public string imageUrlId;////审核通过的图片 ID,微信后台上传审核
            public string query;//查询字符串 必须是 key1=val1&key2=val2 的格式。从这条转发消息进入后，可通过 wx.getLaunchOptionsSync() 或 wx.onShow() 获取启动参数中的 query。不传则默认使用当前页面query。SDK
        }
        public delegate void ShareCallBack(string result);//JSCALLBACKDATA<Dictionary<string, object>> result
        public ShareCallBack shareCallBack = null;
        public void Share(object param, ShareCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            shareCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to share");
            return;
#elif UNITY_WEBGL
                    share(paramStr);
#endif
        }

        public void ShareCallBackFromJs(string result)
        {
            DemoDebugLog("ShareCallBackFromJs:" + result);
            shareCallBack?.Invoke(result);
        }




        /*
        * 调用js 主动分享
        * param 
        * return void
        */
        public delegate void ShareOpenCallBack(string result);//JSCALLBACKDATA<Dictionary<string, object>> result
        public ShareCallBack shareOpenCallBack = null;
        public void ShareOpen(object param, ShareCallBack callBack = null)
        {

            string paramStr = ObjectParamToString(param);
            shareOpenCallBack = callBack;
            //把init 参数转成字符串
#if UNITY_EDITOR
            DemoDebugLog("to shareOpen");
            return;
#elif UNITY_WEBGL
             shareOpen(paramStr);
#endif
        }

        public void ShareOpenCallBackFromJs(string result)
        {
            DemoDebugLog("ShareOpenCallBackFromJs:" + result);
            shareOpenCallBack?.Invoke(result);
        }
        /*
        * 调用js 客服
        * param 
        * return void
        */
        [System.Serializable]
        public class OpenCustomerServiceData
        {
        }
        public delegate void OpenCustomerServiceCallBack(string result);//JSCALLBACKDATA<Dictionary<string, object>> result
        public OpenCustomerServiceCallBack openCustomerServiceCallBack = null;
        public void OpenCustomerService(object param, OpenCustomerServiceCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            openCustomerServiceCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to openCustomerService");
            return;
#elif UNITY_WEBGL
            openCustomerService(paramStr);
#endif
        }
        public void OpenCustomerServiceCallBackFromJs(string result)
        {
            DemoDebugLog("OpenCustomerServiceCallBackFromJs:" + result);
            openCustomerServiceCallBack?.Invoke(result);
        }

        /*
        * 调用js 获取用户信息
        * param 
        * return void
        */
        [System.Serializable]
        public class GetUserInfoData
        {
        }
        public delegate void GetUserInfoCallBack(string result);//JSCALLBACKDATA<Dictionary<string, object>> result
        public GetUserInfoCallBack getUserInfoCallBack = null;
        public void GetUserInfo(object param, GetUserInfoCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            getUserInfoCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to getUserInfo");
            return;
#elif UNITY_WEBGL
            getUserInfo(paramStr);
#endif
        }


        public void GetUserInfoCallBackFromJs(string result)
        {
            DemoDebugLog("GetUserInfoCallBackFromJs:" + result);
            getUserInfoCallBack?.Invoke(result);
        }
        /*
        * 调用js 授权按钮
        * param 
        * return void
        */
        [System.Serializable]
        public class CreateUserInfoButtonData
        {
        }
        public delegate void CreateUserInfoButtonCallBack(string result);//JSCALLBACKDATA<Dictionary<string, object>> result
        public CreateUserInfoButtonCallBack createUserInfoButtonCallBack = null;
        public void CreateUserInfoButton(object param, CreateUserInfoButtonCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            createUserInfoButtonCallBack = callBack;
            //把init 参数转成字符串
#if UNITY_EDITOR
            DemoDebugLog("to createUserInfoButton");
            return;
#elif UNITY_WEBGL
            createUserInfoButton(paramStr);
#endif
        }

        public void CreateUserInfoButtonCallBackFromJs(string result)
        {
            DemoDebugLog("CreateUserInfoButtonCallBackFromJs:" + result);
            createUserInfoButtonCallBack?.Invoke(result);
        }



        /*
         * 取消授权铵钮
         * @param initData:object   callBack:InitCallBack//回调方法 非必传
         * @return void 
         */
        public delegate void DestoryUserInfoButtonCallBack(string result);
        public DestoryUserInfoButtonCallBack destoryUserInfoButtonCallBack = null;
        public void DestoryUserInfoButton(object param, DestoryUserInfoButtonCallBack callBack = null)
        {
            string initParam = ObjectParamToString(param);
            destoryUserInfoButtonCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("destoryUserInfoButton func");
            return;
#elif UNITY_WEBGL
            destoryUserInfoButton(initParam);
#endif
        }

        /*
         * 调用js 取消授权铵钮->js回调
         * param 
         * return void
         */
        public void DestoryUserInfoButtonFromJs(string result)
        {
            destoryUserInfoButtonCallBack?.Invoke(result);
        }

        /*
        * 调用js 创建角色
        * param 
        * return void
        */
        [System.Serializable]
        public class CreateRoleData
        {
        }
        public delegate void CreateRoleCallBack(string result);//JSCALLBACKDATA<Dictionary<string, object>> result
        public CreateRoleCallBack createRoleCallBack = null;
        public void CreateRole(object param, CreateRoleCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            createRoleCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to createRole");
            return;
#elif UNITY_WEBGL
            createRole(paramStr);
#endif
        }

        public void CreateRoleCallBackFromJs(string result)
        {
            DemoDebugLog("CreateRoleCallBackFromJs:" + result);
            createRoleCallBack?.Invoke(result);
        }


        /*
        * 调用js 登录角色
        * param 
        * return void
        */
        [System.Serializable]
        public class LoginRoleData
        {
        }
        public delegate void LoginRoleCallBack(string result);//JSCALLBACKDATA<Dictionary<string, object>> result
        public LoginRoleCallBack loginRoleCallBack = null;
        public void LoginRole(object param, LoginRoleCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            loginRoleCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to loginRole");
            return;
#elif UNITY_WEBGL
            loginRole(paramStr);
#endif
        }
        public void LoginRoleCallBackFromJs(string result)
        {
            DemoDebugLog("LoginRoleCallBackFromJs:" + result);
            loginRoleCallBack?.Invoke(result);
        }



        /*
      * 调用js 切换角色
      * param 
      * return void
      */
        public delegate void ChangeRoleCallBack(string result);//JSCALLBACKDATA<Dictionary<string, object>> result
        public CreateRoleCallBack changeRoleCallBack = null;

        public void ChangeRole(object param, CreateRoleCallBack callBack = null)
        {

            string paramStr = ObjectParamToString(param);
            changeRoleCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to changeRole");
            return;
#elif UNITY_WEBGL
            changeRole(paramStr);
#endif
        }

        public void ChangeRoleCallBackFromJs(string result)
        {
            DemoDebugLog("CreateRoleCallBackFromJs:" + result);
            changeRoleCallBack?.Invoke(result);
        }



        /*
        * 调用js 上报其他数据
        * param 
        * return void
        */
        [System.Serializable]
        public class ReportLogData
        {
        }
        public delegate void ReportLogCallBack(string result);//JSCALLBACKDATA<Dictionary<string, object>> result
        public ReportLogCallBack reportLogCallBack = null;
        public void ReportLog(object param, ReportLogCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            reportLogCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to reportLog");
            return;
#elif UNITY_WEBGL
                    reportLog(paramStr);
#endif
        }
        public void ReportLogCallBackFromJs(string result)
        {
            DemoDebugLog("ReportLogCallBackFromJs:" + result);
            reportLogCallBack?.Invoke(result);
        }

        /*
        * 调用js 上报引力引擎
        * param 
        * return void
        */
        public delegate void YlyqReportCallBack(string result);//JSCALLBACKDATA<Dictionary<string, object>> result
        public ReportLogCallBack ylyqReportCallBack = null;
        public void YlyqReport(object param, ReportLogCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            ylyqReportCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to ylyqReport");
            return;
#elif UNITY_WEBGL
                    ylyqReport(paramStr);
#endif
        }
        public void YlyqReportCallBackFromJs(string result)
        {
            DemoDebugLog("YlyqReportCallBackFromJs:" + result);
            ylyqReportCallBack?.Invoke(result);
        }


        /*
        * 调用js 上报数数
        * param 
        * return void
        */
        public delegate void SsReportCallBack(string result);//JSCALLBACKDATA<Dictionary<string, object>> result
        public ReportLogCallBack ssReportCallBack = null;
        public void SsReport(object param, ReportLogCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            ssReportCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to ssReport");
            return;
#elif UNITY_WEBGL
                    ssReport(paramStr);
#endif
        }
        public void SsReportCallBackFromJs(string result)
        {
            DemoDebugLog("SsReportCallBackFromJs:" + result);
            ssReportCallBack?.Invoke(result);
        }



        /*
        * 调用js 设置用户属性
        * param 
        * return void
        */
        public delegate void SsUserSetCallBack(string result);//JSCALLBACKDATA<Dictionary<string, object>> result
        public ReportLogCallBack ssUserSetCallBack = null;
        public void SsUserSet(object param, ReportLogCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            ssUserSetCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to ssUserSet");
            return;
#elif UNITY_WEBGL
                    ssUserSet(paramStr);
#endif
        }
        public void SsUserSetCallBackFromJs(string result)
        {
            DemoDebugLog("SsReportCallBackFromJs:" + result);
            ssUserSetCallBack?.Invoke(result);
        }
        /*
        * 调用js 自定义按钮1
        * param 
        * return void
        */
        [System.Serializable]
        public class ButtonOneData
        {
        }
        public delegate void ButtonOneCallBack(string result);//JSCALLBACKDATA<Dictionary<string, object>> result
        public ButtonOneCallBack buttonOneCallBack = null;
        public void ButtonOne(object param, ButtonOneCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            buttonOneCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to buttonOne");
            return;
#elif UNITY_WEBGL
                    buttonOne(paramStr);
#endif
        }
        public void ButtonOneCallBackFromJs(string result)
        {
            DemoDebugLog("ButtonOneCallBackFromJs:" + result);
            buttonOneCallBack?.Invoke(result);
        }


        /*
        * 调用js 自定义按钮2
        * param 
        * return void
        */
        [System.Serializable]
        public class ButtonTwoData
        {
        }
        public delegate void ButtonTwoCallBack(string result);
        public ButtonTwoCallBack buttonTwoCallBack = null;
        public void ButtonTwo(object param, ButtonTwoCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            buttonTwoCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to buttonTwo");
            return;
#elif UNITY_WEBGL
                    buttonTwo(paramStr);
#endif
        }

        public void ButtonTwoCallBackFromJs(string result)
        {
            DemoDebugLog("ButtonTwoCallBackFromJs:" + result);
            buttonTwoCallBack?.Invoke(result);
        }


        //sdk 2.0
        /*
        * 调用js 加入语音房间
        * param 
        * return void
        */
        public delegate void JoinVoIPChatCallBack(string result);
        public delegate void JoinVoIPChatListenCallBack(string result);
        public JoinVoIPChatCallBack joinVoIPChatCallBack = null;
        public JoinVoIPChatListenCallBack joinVoIPChatListenCallBack = null;
        public void JoinVoIPChat(object param, JoinVoIPChatCallBack callBack = null, JoinVoIPChatListenCallBack callBackListen = null)
        {
            string paramStr = ObjectParamToString(param);
            joinVoIPChatCallBack = callBack;
            joinVoIPChatListenCallBack = callBackListen;
#if UNITY_EDITOR
            DemoDebugLog("to JoinVoIPChat");
            return;
#elif UNITY_WEBGL
            joinVoIPChat(paramStr);
#endif
        }

        /*
        * 调用js 加入语音房间-操作回调
        * param 
        * return void
        */
        public void JoinVoIPChatCallBackFromJs(string result)
        {
            DemoDebugLog("JoinVoIPChatCallBackFromJs:" + result);
            joinVoIPChatCallBack?.Invoke(result);
        }

        /*
        * 调用js 加入语音房间-实时回调（有人加入房间 退出房间）
        * param 
        * return void
        */
        public void JoinVoIPChatListenCallBackFromJs(string result)
        {
            DemoDebugLog("JoinVoIPChatListenCallBackFromJs:" + result);
            joinVoIPChatListenCallBack?.Invoke(result);
        }


        /*
        * 调用js - 退出语音房间
        * param 
        * return void
        */
        public delegate void ExitVoIPChatCallBack(string result);
        public ExitVoIPChatCallBack exitVoIPChatCallBack = null;
        public void ExitVoIPChat(object param, ExitVoIPChatCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            exitVoIPChatCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to ExitVoIPChat");
            return;
#elif UNITY_WEBGL
            exitVoIPChat(paramStr);
#endif
        }

        /*
        * 调用js 加入语音房间-操作回调
        * param 
        * return void
        */
        public void ExitVoIPChatCallBackFromJs(string result)
        {
            DemoDebugLog("ExitVoIPChatCallBackFromJs:" + result);
            exitVoIPChatCallBack?.Invoke(result);
        }

        /*
        * 调用js - - 更新实时语音静音设置
        * param 
        * return void
        */
        public delegate void UpdateVoIPChatMuteConfigCallBack(string result);
        public UpdateVoIPChatMuteConfigCallBack updateVoIPChatMuteConfigCallBack = null;
        public void UpdateVoIPChatMuteConfig(object param, UpdateVoIPChatMuteConfigCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            updateVoIPChatMuteConfigCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to UpdateVoIPChatMuteConfig");
            return;
#elif UNITY_WEBGL
            updateVoIPChatMuteConfig(paramStr);
#endif
        }

        /*
        * 调用js - 更新实时语音静音设置-操作回调
        * param 
        * return void
        */
        public void UpdateVoIPChatMuteConfigCallBackFromJs(string result)
        {
            DemoDebugLog("UpdateVoIPChatMuteConfigCallBackFromJs:" + result);
            updateVoIPChatMuteConfigCallBack?.Invoke(result);
        }

        /*
        * 调用js - 一次性订阅消息
        * param 
        * return void
        */
        public delegate void RequestSubscribeMessageCallBack(string result);
        public RequestSubscribeMessageCallBack requestSubscribeMessageCallBack = null;
        public void RequestSubscribeMessage(object param, RequestSubscribeMessageCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            requestSubscribeMessageCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to RequestSubscribeMessage");
            return;
#elif UNITY_WEBGL
            requestSubscribeMessage(paramStr);
#endif
        }

        /*
        * 调用js -一次性订阅消息设置-操作回调
        * param 
        * return void
        */
        public void RequestSubscribeMessageCallBackFromJs(string result)
        {
            DemoDebugLog("RequestSubscribeMessageCallBackFromJs:" + result);
            requestSubscribeMessageCallBack?.Invoke(result);
        }


        /*
        * 调用js -更新版本消息
        * param 
        * return void
        */
        public delegate void RequestSubscribeSystemMessageCallBack(string result);
        public RequestSubscribeSystemMessageCallBack requestSubscribeSystemMessageCallBack = null;
        public void RequestSubscribeSystemMessage(object param, RequestSubscribeSystemMessageCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            requestSubscribeSystemMessageCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to RequestSubscribeSystemMessage");
            return;
#elif UNITY_WEBGL
            requestSubscribeSystemMessage(paramStr);
#endif
        }

        /*
        * 调用js -更新版本消息-操作回调
        * param 
        * return void
        */
        public void RequestSubscribeSystemMessageCallBackFromJs(string result)
        {
            DemoDebugLog("RequestSubscribeSystemMessageCallBackFromJs:" + result);
            requestSubscribeSystemMessageCallBack?.Invoke(result);
        }


        /*
        * 调用js -检查是否加入收藏
        * param 
        * return void
        */
        public delegate void CheckIsAddedToMyMiniProgramCallBack(string result);
        public CheckIsAddedToMyMiniProgramCallBack checkIsAddedToMyMiniProgramCallBack = null;
        public void CheckIsAddedToMyMiniProgram(object param, CheckIsAddedToMyMiniProgramCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            checkIsAddedToMyMiniProgramCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to CheckIsAddedToMyMiniProgram");
            return;
#elif UNITY_WEBGL
            checkIsAddedToMyMiniProgram(paramStr);
#endif
        }

        /*
        * 调用js -检查是否加入收藏-操作回调
        * param 
        * return void
        */
        public void CheckIsAddedToMyMiniProgramCallBackFromJs(string result)
        {
            DemoDebugLog("CheckIsAddedToMyMiniProgramCallBackFromJs:" + result);
            checkIsAddedToMyMiniProgramCallBack?.Invoke(result);
        }


        /*
        * 调用js --激励广告2
        * param 
        * return void
        */
        public delegate void RewardVideoAdCreate2CallBack(string result);
        public RewardVideoAdCreate2CallBack rewardVideoAdCreate2CallBack = null;
        public void RewardVideoAdCreate2(object param, RewardVideoAdCreate2CallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            rewardVideoAdCreate2CallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to RewardVideoAdCreate2");
            return;
#elif UNITY_WEBGL
            rewardVideoAdCreate2(paramStr);
#endif
        }

        /*
        * 调用js -- 激励广告2
        * param 
        * return void
        */
        public void RewardVideoAdCreate2CallBackFromJs(string result)
        {
            DemoDebugLog("RewardVideoAdCreate2CallBackFromJs:" + result);
            rewardVideoAdCreate2CallBack?.Invoke(result);
        }


        /*
        * 调用js -获取用户当前位置信息
        * param 
        * return void
        */
        public delegate void GetLocationCallBack(string result);
        public GetLocationCallBack getLocationCallBack = null;
        public void GetLocation(object param, GetLocationCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            getLocationCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to GetLocation");
            return;
#elif UNITY_WEBGL
            getLocation(paramStr);
#endif
        }

        /*
        * 调用js -- 激励广告2
        * param 
        * return void
        */
        public void GetLocationCallBackFromJs(string result)
        {
            DemoDebugLog("GetLocationCallBackFromJs:" + result);
            getLocationCallBack?.Invoke(result);
        }


        /*
        * 调用js -获取用户当前位置信息
        * param 
        * return void
        */
        public delegate void GetSettingCallBack(string result);
        public GetSettingCallBack getSettingCallBack = null;
        public void GetSetting(object param, GetSettingCallBack callBack = null)
        {
            string paramStr = ObjectParamToString(param);
            getSettingCallBack = callBack;
#if UNITY_EDITOR
            DemoDebugLog("to GetSetting");
            return;
#elif UNITY_WEBGL
            getSetting(paramStr);
#endif
        }

        /*
        * 调用js -- 激励广告2
        * param 
        * return void
        */
        public void GetSettingCallBackFromJs(string result)
        {
            DemoDebugLog("GetSettingCallBackFromJs:" + result);
            getSettingCallBack?.Invoke(result);
        }
        #endregion  --------------调用js结束方法---------------------

        public void DemoDebugLog(string debugContent)
        {
            if (isDemoDebug)
            {
                Debug.Log(debugContent);
            }
        }
    }


    [System.Serializable]
    public class JSCALLBACKDATA<T>
    {
        public int code;
        public string message;
        public T data;
    }



    [System.Serializable]
    public class LoginCallbackData
    {
        public string loginType;
        public string loginStatus;
        public Dictionary<string, object> customProperties;
    }



}
