Special treatment for lottery games

This function is mainly to facilitate the interaction between merchants and users on results. For example, some live broadcast apps and live lottery broadcasts need to obtain the results of each lotte

Lottery notification embedding function and example

Lottery notification embedding function and example: After embedding through ifame, obtain betting and lottery information

General code example (see attachment for details)

Code Sample

<script type="text/javascript">
const iframe = document.getElementById('myIframe');
// Basic format for sending data
const postData = { 
    action: 'sendData',
    data: { 
        op: "Follow",
        data: {} 
    }
}
// Follow-up investment
const FollowUpInvestment = () => {
    if(!postData.data.data){
        return;
    }
    iframe.contentWindow.postMessage(JSON.stringify(postData), '*');
}
// Get betting information
const getBetInfo = (data) => {
    document.querySelectorAll('#FollowUp-info h4')[0].innerHTML = JSON.stringify(data);
    postData.data.data = data;
}
// Get lottery result information
const getPrizeInfo = (data) => {
    let { roundId, nums, tags } = data;
    document.querySelectorAll('#Prize-Information h4')[0].innerHTML = `Round ID: ${roundId} Lottery Result: ${nums}******${tags}`
}
// Get reward information
const getRewardInfo = (data) => {
    console.log(data)
}
// Callback function
const callbackFunc = (arg) => {
    const { op, data } = arg;
    switch (op) {
        case 'Bet':
            getBetInfo(data)
            break;
        case 'ShowRound':
            getPrizeInfo(data)
            break;
        case 'Reward':
            getRewardInfo(data)
            break;
        default:
            break;
    }
}
// Listen for messages
((window,iframe) => {
    iframe.onload = function() {
        window.addEventListener('message', function(event) {
            var { action, data } = JSON.parse(event.data);
            if (action === 'sendData') {
                callbackFunc(data)
            }
        });
    }
})(window,iframe)
</script>

Android uses webview to initialize the game, which requires the injection interface. Example steps

// Sample Code
// 1. Create an interface class
    class AndroidInterface {
        @JavascriptInterface
        fun showToast(message: String) {
        // Handling calls from JS
        }
    }

// 2. Injection interface
    webView.addJavascriptInterface(AndroidInterface(), "Android")

// 3. Check after the page has loaded
    webView.setWebViewClient(object : WebViewClient() {
        override fun onPageFinished(view: WebView?, url: String?) {
            super.onPageFinished(view, url)
                
            // Check if an Android object exists
            webView.evaluateJavascript("typeof window.Android") { result ->
                Log.d("WebViewConsole", "Android object type: $result")
            // If "object" is returned, the injection is successful.
            }
        }
    })

Last updated