private void button7_Click(object sender, EventArgs e) { var appId = tb_appId.Text.Trim(); var appSecret = tb_appSecret.Text.Trim(); ApiAccessTokenManager.Instance.SetAppIdentity(appId, appSecret); IApiClient client = new DefaultApiClient(); var request = new MediaUploadRequest { AccessToken = ApiAccessTokenManager.Instance.GetCurrentToken(), MediaType = GetMediaType(), FilePath = textBox1.Text }; var response = client.Execute(request); if (response.IsError) { MessageBox.Show("错误:" + response.ErrorMessage); } else { MessageBox.Show("保存成功!mediaid:" + response.MediaId); } }
public void GetAccessTokenCore() { var appid = new AppIdentication("wx7fc05579394bd02c", "26f8f072c53e97d0033e3589e7de4e84"); var request = new AccessTokenRequest(appid); IApiClient client = new DefaultApiClient(); var response = client.Execute(request); Console.WriteLine(response.ToString()); }
public void TestMethod1() { IApiClient client = new DefaultApiClient("http://apis.7moor.com", "xxxx", "xxxx"); //ºô³ö CallDialoutRequest callDialoutRequest = new CallDialoutRequest("8002", "18888888888"); CallDialoutResponse callDialoutResponse = client.Execute(callDialoutRequest); Assert.IsNull(callDialoutResponse); }
private void button5_Click(object sender, EventArgs e) { var appId = tb_appId.Text.Trim(); var appSecret = tb_appSecret.Text.Trim(); if (String.IsNullOrEmpty(appId) || String.IsNullOrEmpty(appSecret)) { MessageBox.Show("请输入appId和appSecret"); return; } if (Rows == null || !Rows.Any()) { MessageBox.Show("请添加菜单"); return; } ApiAccessTokenManager.Instance.SetAppIdentity(appId, appSecret); IApiClient client = new DefaultApiClient(); var request = new MenuCreateRequest() { AccessToken = ApiAccessTokenManager.Instance.GetCurrentToken(), Buttons = BuildButton() }; var response = client.Execute(request); if (response.IsError) { MessageBox.Show(response.ToString()); return; } else { MessageBox.Show("菜单生成成功,一般有24小时缓存时间,也可以直接取消关注再关注直接查看效果"); } }
public void ProcessRequest(HttpContext context) { var accesstoken = CookiesHelper.GetCookie(accesstokenKey); SnsOAuthAccessTokenResponse AccessToken = null; var m_client = new DefaultApiClient(); var m_appIdent = new AppIdentication(wxappid, wxappsecret); string State = context.Request["state"]; string jumpUrl = "index.html"; try { if (accesstoken == null) { string code = context.Request["Code"]; var request = new SnsOAuthAccessTokenRequest { AppID = m_appIdent.AppID, AppSecret = m_appIdent.AppSecret, Code = code }; AccessToken = m_client.Execute(request); if (AccessToken.IsError) { throw new Exception("获取网页授权accesstoken失败。" + JsonHelper.ReBuilder(request) + "\r\n" + AccessToken.ErrorMessage); } CookiesHelper.AddCookie("webpage_accesstoken", JsonHelper.ReBuilder(AccessToken), DateTime.Now.AddSeconds(AccessToken.ExpiresIn - 600)); } else { AccessToken = JsonHelper.Build <SnsOAuthAccessTokenResponse>(accesstoken.Value); } string unionid = AccessToken.UnionId; if (String.IsNullOrEmpty(unionid)) { unionid = AccessToken.OpenId; } string openid = AccessToken.OpenId; var query = new RequestOperation <string>(); query.Header = new HeaderInfo() { DeviceID = 5, DisplayName = "customer", UserID = 1 }; query.Body = unionid; var service = new CustomerBP(); var data = service.LoginByWechatAccount(query); //不存在此用户 if (data.ErrCode == 1) { var wexinInfo = new SnsUserInfoRequest { OAuthToken = AccessToken.AccessToken, OpenId = AccessToken.OpenId, Lang = Language.CN }; var userinfo_res = m_client.Execute(wexinInfo); if (userinfo_res.IsError) { throw new Exception("获取用户信息失败2。" + JsonHelper.ReBuilder(wexinInfo) + "\r\n" + JsonHelper.ReBuilder(userinfo_res)); } #region 注册 string url = HttpUtility.UrlDecode(State); int invateUserId = 0; if (!string.IsNullOrEmpty(State)) { url = domian + unescape(url); invateUserId = getInveteUser(url); } var register = new RequestOperation <RegisterData>(); register.Header = query.Header; register.Body = new RegisterData(); register.Body.Account = ""; register.Body.WechatAccount = unionid; register.Body.QQAccount = ""; register.Body.Face = userinfo_res.HeadImageUrl; register.Body.NickName = register.Body.Name = userinfo_res.NickName; register.Body.Password = "******"; var register_res = service.Register(register); if (register_res.ErrCode != 0) { throw new Exception("注册用户失败:" + register_res.Message); } LoginManage.SaveUserWeixinOpenId(userinfo_res.OpenId); LoginManage.SaveUserInfo(register_res.Body.UserID); if (!string.IsNullOrEmpty(State)) { jumpUrl = replaceInveteUserParam(url); } #endregion } else { //不准修改,此处用于微信支付!!! LoginManage.SaveUserWeixinOpenId(AccessToken.OpenId); LoginManage.SaveUserInfo(data.Body.UserID); if (!string.IsNullOrEmpty(State)) { string url = domian + HttpUtility.UrlDecode(State); jumpUrl = replaceInveteUserParam(url); } } } catch (Exception ex) { Logger.WriteException("【微信网页授权】", ex, ""); } context.Response.Redirect(jumpUrl); }