chicken_dy/Assets/HCMiniSdk/Scripts/WebGL/HCWX/HCWXAccount.cs

45 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#if UNITY_WEBGL && WEBGL_WX
using System;
using System.Collections.Generic;
using WeChatWASM;
namespace HC
{
public class HCWXAccount : HCIAccount
{
public void Login(Action<HCLoginResult> action)
{
HCDebugger.LogDebug("[HCWXAccount] [Login] Start");
WX.Login(new LoginOption
{
complete = generalCallbackResult => { HCDebugger.LogDebug($"[HCWXAccount] [Login] complete {generalCallbackResult.errMsg}"); },
fail = err =>
{
HCDebugger.LogDebug($"[HCWXAccount] [Login] fail {err.errMsg} {err.errno}");
action?.Invoke(new HCLoginResult
{
code = -1,
msg = err.errMsg
});
},
success = result =>
{
// 用户登录凭证(有效期五分钟)。开发者需要在开发者服务器后台调用 code2Session使用 code 换取 openid、unionid、session_key 等信息
var resultCode = result.code;
var resultErrMsg = result.errMsg;
HCDebugger.LogDebug($"[HCWXAccount] [Login] success result code = {resultCode} result err msg = {resultErrMsg}");
action?.Invoke(new HCLoginResult()
{
code = 0,
token = resultCode,
userId = resultCode,
ext = new Dictionary<string, object>()
});
},
});
}
}
}
#endif