Jiguang SDK API access document

1. Add submodule

Add the warehouse address of the SDK code to your own project as a submodule through sourceTree. Then update the submodule and pull it to the latest.

2. Mount the C# script

Create an empty GameObject in the main scene of the game startup, and name it sdk , and then mount the two C# scripts, JIMClientAPI and JIMTalkAPI , pulled from Jim_sdk/Scripts/JIM/api to the empty GameObject sdk.

3. Get the C# script

function _M:init()
    local sdk_ob = CS.UnityEngine.GameObject.Find("sdk")
    jim_client_api = sdk_ob:GetComponent("JIMClientAPI")
    jim_talk_api = sdk_ob:GetComponent("JIMTalkAPI")

    -- 回调事件注册
    jim_talk_api.onRegisterEvent = U.handle(self, self.on_register)
    jim_talk_api.onLoginEvent = U.handle(self, self.on_login)
    jim_talk_api.onRecTextMsg = U.handle(self, self.on_rec_text_msg)
    jim_talk_api.onRecChatRoomTextMsg = U.handle(self, self.on_rec_chatroom_text_msg)    
end

4. Introduction to Jiguang Interface

Basically the calling interface is in JIMClientAPI script.

Interface calling method specific function
InitSDK(isRoaming:bool) Initialize the SDK, parameter: isRoaming whether message roaming bool value
Register(account:string,token:string) Jiguang sdk registered user, parameters: account is the account ID, token is the account password, both of which are of String type
LoginSDK(account:string,token:string) Jiguang sdk user login, parameters: account is the account ID, token is the account password, both of which are of String type
LogoutSDK() Jiguang sdk user logout, no parameters.
SendTextMsg(appKey:string,account:string,content:string) Single chat to send text messages, parameters: appKey is the key of the application, account is the account ID to which the message needs to be sent, content is the text content of the message, all of String type
EnterChatRoom(roomID:long) Enter the specified chat room, parameters: roomID is the ID of the chat room. Type: long integer
QuitChatRoom(roomID:long) Exit the specified chat room, parameters: roomID is the ID of the chat room. Type: long integer
SendChatRoomMsg(roomID:long,content:string,msg_type:string) The chat room is used to send messages. Parameters: roomID is the chat room ID, content is the text content of the message, msg_type : the message type, a string type, "1" means sending a text message, and "2" means sending a picture message.

Example of a Lua call:

-- 注册接口
function _M:register(param)
    local json_str = U.json.encode(param)
    U.log.i(json_str)
    jim_client_api:Register(json_str)
end

Event callback form

callback name specific function
OnRegisterEvent () Register a callback and return a table containing two parameters, response_code Int type parameter, 0 means success, otherwise it means failure. desc is error description information, String type.
OnLoginEvent() Login callback, return a form, which contains a response_code Int type parameter, 0 means success, otherwise it means failure. desc is error description information, String type.
OnRecTextMsg() Received single chat message callback, callback parameters: a form, source_name message source user id, content message content, msg_type message type. All are String type
OnRecChatRoomTextMsg() Receive chat room message callback, callback parameters: a table, including cid message id, source_name message source user id, content message content, msg_type message type. All are String type
    -- 回调事件注册
    jim_talk_api.onRegisterEvent = U.handle(self, self.on_register)
    jim_talk_api.onLoginEvent = U.handle(self, self.on_login)
    jim_talk_api.onRecTextMsg = U.handle(self, self.on_rec_text_msg)
    jim_talk_api.onRecChatRoomTextMsg = U.handle(self, self.on_rec_chatroom_text_msg)

Callback for TODO
user login status change Callback for
single chat sending message Callback
for entering chat room Callback for
exiting chat room Callback
for sending message in chat room

Guess you like

Origin blog.csdn.net/a525324105/article/details/106993655