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

45 lines
1.6 KiB
C#
Raw Permalink Normal View History

2024-03-07 12:12:48 +00:00
#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