public async Task GetTokenShouldSuccess() { IWeChatClient client = new DefaultClient(ServerUrl, AppId, AppSecret); var request = new GetAccessTokenReqeust(); var result = await client.GetAccessToken(request); Assert.NotNull(result.AccessToken); Assert.True(result.ExpiresIn > 0); }
public async Task MessageTemplateSendShouldSuccess() { IWeChatClient client = new DefaultClient(ServerUrl, AppId, AppSecret); var requestToken = new GetAccessTokenReqeust(); var resultToken = await client.GetAccessToken(requestToken); var token = resultToken.AccessToken; var request = new MessageTemplateSendRequest <Template>(); var model = new MessageTemplateSendModel <Template>(); model.ToUser = OpenID; model.TemplateId = TemplateId; model.Template = new Template { Head = new TemplateContent { Value = "恭喜你购买成功!", Color = "#173177" }, ProductName = new TemplateContent { Value = "巧克力", Color = "#173177" }, TotalPrice = new TemplateContent { Value = "39.8元", Color = "#173177" }, PayTime = new TemplateContent { Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Color = "#173177" }, Remark = new TemplateContent { Value = "欢迎再次购买!", Color = "#173177" } }; request.Parameters = model; var result = await client.Execute(request, token); Assert.True(result.ErrorCode == 0); }
public async Task GetUserInfo_ShouldSuccess_WithExpectedParameters() { GetUserInfoModel model = new GetUserInfoModel { OpenID = OpenID }; IWeChatClient client = new DefaultClient(ServerUrl, AppId, AppSecret); var requestToken = new GetAccessTokenReqeust(); var resultToken = await client.GetAccessToken(requestToken); var token = resultToken.AccessToken; var request = new GetUserInfoRequest(); request.Parameters = model; var result = await client.Execute(request, token); Assert.True(result.ErrorCode == 0); }