public Webzalo() { InitializeComponent(); Zalo3rdAppInfo appInfo = new Zalo3rdAppInfo(2683610687619458655, "ONr32QXPrsW53C4eD5dA", "https://youruri.com"); Zalo3rdAppClient appClient = new Zalo3rdAppClient(appInfo); string loginUrl = appClient.getLoginUrl(); string code = ""; JObject token = appClient.getAccessToken(code); //zaloweb.Source =; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { tranghientai = "localhost:1834/zalo.aspx"; Zalo3rdAppClient appClient = new Zalo3rdAppClient(new Zalo3rdAppInfo(2127518896466871150, "OUKlCdL8uYLIMe73QB65", tranghientai)); string loginUrl = appClient.getLoginUrl(); code = Request.QueryString["code"]; JObject token = appClient.getAccessToken(code); if (string.IsNullOrEmpty(code)) { Response.Redirect(loginUrl.ToString()); } else { string chuoitoken = token.Property("access_token").Value.ToString(); JObject profile = appClient.getProfile(chuoitoken, "name,picture,id,userIdByOA"); // userIdByOA => ID cần gửi tin txtHDinfo.Value = profile.ToString(); //txtTenNguoiDung.Text = profile.Property("name").Value.ToString(); txtTenNguoiDung.Text = "NTSoft"; JObject invitableFriends = appClient.getInvitableFriends(chuoitoken, 0, 0, "id, name, picture, gender"); int soluong = 0; soluong = int.Parse(invitableFriends["summary"]["total_count"].ToString()); //JObject banbe = appClient.getInvitableFriends(chuoitoken, 0, soluong, "id, name, picture, gender,userIdByOA"); JObject banbe = JObject.Parse(JObject.Parse(new WebClient().DownloadString("https://openapi.zalo.me/v2.0/oa/getfollowers?access_token=w8i4LtUoispYX0XGUxoyOk633rryexLkf-1d5N-lg6-twqXHLRs2Q8dZH54MtvCfmfqXG2ltwtBMcoPA7lVnTSMD94WZnUGQ-89M91Yua6F-yoDS5CdZ8y-39s8szEymwhqQ3t_gqZ7ZfHft1CV83kg267HtkiWuWkv_V6oYgpwnWKX6RkkcVx6HTZ9Gsy9PZu4r6NRMW27hW4qV0CU4TfYdGZL-neDLw_bFQ16D_JNij0S86SB8OVFx6IOfagaSnVb9JmcVWn_qw5DIhGw22dQhj6m&data={offset=0,count=5}"))["data"].ToString()); string[,] mangid = new string[banbe["followers"].Count <JToken>(), 3]; ZaloOaInfo zaloOaInfo = new ZaloOaInfo(739460368435099423, "n30YrpHUT626CuAUWW15"); ZaloOaClient oaClient = new ZaloOaClient(zaloOaInfo); for (int i = 0; i < banbe["followers"].Count <JToken>(); i++) { long idphu = long.Parse(banbe["followers"][i].Value <JToken>()["user_id"].ToString()); JObject a1 = oaClient.getProfile(idphu); mangid[i, 0] = idphu.ToString(); mangid[i, 1] = a1["data"].Value <JToken>()["avatar"].ToString(); mangid[i, 2] = a1["data"].Value <JToken>()["displayName"].ToString(); } json_dsbb = JsonConvert.SerializeObject(mangid); } } catch (Exception ex) { Response.Write(ex.Message); } } }
public async Task <IActionResult> ZaloCallback(string code, string state) { Zalo3rdAppInfo appInfo = new Zalo3rdAppInfo(Int64.Parse(_externalProvider.Value.Zalo.AppId), _externalProvider.Value.Zalo.SecretCode, _externalProvider.Value.Zalo.CallbackUrl); Zalo3rdAppClient appClient = new Zalo3rdAppClient(appInfo); JObject token = appClient.getAccessToken(code); var accessToken = token["access_token"].ToString(); JObject profile = appClient.getProfile(accessToken, "name, id, picture"); var tmpData = profile.ToObject <ExternalUserModel>(); var user = await _userStoreExtend.FindByNameAsync("Zalo" + tmpData.id); if (user != null) { #region Get user zalo var permissions = await _roleStoreExtend.ReadByUser(user.Id); var userInfo = _mapper.Map <UserInfo>(user); userInfo.Permissions = permissions; string[] output = userInfo.FullName.Split(' '); foreach (string s in output) { userInfo.LetterAvatar += s[0]; } userInfo.Avatar = (userInfo.Avatar == null ? "" : _imagePath.Value.URL + userInfo.Avatar); userInfo.PhoneNumber = (userInfo.PhoneNumber == null ? "" : userInfo.PhoneNumber); userInfo.LetterAvatar = userInfo.LetterAvatar.ToUpper(); #endregion var responseLogin = new ResponseNotification(); var response = new Response(); responseLogin.type = 1; response.response = userInfo; responseLogin.response = response; //await PushNotification(state, "Okaylah", "Đăng nhập zalo thành công", "Success", JsonConvert.SerializeObject(responseLogin)); } else { var responseLogin = new ResponseNotification(); responseLogin.type = 1; var responseEr = new ResponseError(); responseEr.status = "404"; responseEr.response = accessToken; responseLogin.response = responseEr; //await PushNotification(state, "Okaylah", "Đăng nhập zalo thất công", "Register", JsonConvert.SerializeObject(responseLogin)); } return(Ok()); }
static void Main(string[] args) { long appId = 400935361715655638; string secretKey = "Cp31r0OxUdbX1UGGDG5z"; string callbackUrl = "http://zalo.iot.vn/api/notify/zalo/zalo_redirect_uri"; var appClient = new Zalo3rdAppClient(new ZaloAppInfo(appId, secretKey, callbackUrl)); //http://zalo.iot.vn/login.html?invitesrc=openapi&utm_source=zalo&utm_medium=zalo&utm_campaign=zalo&zarsrc=30 //https://oauth.zaloapp.com/v3/auth?app_id=4493888734077794545&redirect_uri=http://zalo.iot.vn/ok.html string loginUrl = appClient.getLoginUrl(); //https://id.zalo.me/account/login?continue=https%3A%2F%2Foauth.zaloapp.com%2Fv3%2Fauth%3Fapp_id%3D4493888734077794545%26redirect_uri%3Dhttp%3A%2F%2Fzalo.iot.vn%2Fok.html //https://id.zalo.me/account/login?continue=https://oauth.zaloapp.com/v3/auth?app_id=4493888734077794545&redirect_uri=http://zalo.iot.vn/ok.html //http://zalo.iot.vn/ok.html?uid=2119814009048858734&code=la7-NfakZGFoVkLGjYAyM_LKfXJX7Snwk5VS7BKvWMshOUC3_JQ8Nk1LqaIP7iu2Z5AbPDychHF-TSrWxo-h3BHwmbFx8x9tiLoN89Sg_aR5VU4RnYs0Pyzru0_IDwvvuZQ4EyKbpcFLSwOKbrtd5jvGnI3PTC9UXYQp1S1empwK8TnoaI6o4T9usmsFTkiVpNxpADSpcN2TS_fjzYIQKeT3Zqd16ijCXns-JiKKXd-2LffyZLUdCkaVkclyIT44fWdpHhfRbYFEKACSqbjSGQyqB1pbUmDBn4DJ7AOQV7DhQ75hR0GYDLf7DBOdAMITJGSFlKiwSxW45mMD3o1wWG0508y_9mZ71sqAoHXCU9XGZX5lboYh6m&scope=access_profile,access_friends_list,send_msg,push_feed long uid = 2119814009048858734; string code = "la7-NfakZGFoVkLGjYAyM_LKfXJX7Snwk5VS7BKvWMshOUC3_JQ8Nk1LqaIP7iu2Z5AbPDychHF-TSrWxo-h3BHwmbFx8x9tiLoN89Sg_aR5VU4RnYs0Pyzru0_IDwvvuZQ4EyKbpcFLSwOKbrtd5jvGnI3PTC9UXYQp1S1empwK8TnoaI6o4T9usmsFTkiVpNxpADSpcN2TS_fjzYIQKeT3Zqd16ijCXns-JiKKXd-2LffyZLUdCkaVkclyIT44fWdpHhfRbYFEKACSqbjSGQyqB1pbUmDBn4DJ7AOQV7DhQ75hR0GYDLf7DBOdAMITJGSFlKiwSxW45mMD3o1wWG0508y_9mZ71sqAoHXCU9XGZX5lboYh6m"; string scope = "access_profile,access_friends_list,send_msg,push_feed"; // { "expires_in": "3600", "access_token": " //4KvSI2BvOYKGIbT4Albc9Xb9LKScupLH61PwRM3yINyr7H1pHQrZGZv8AJfhXtrVKt4tHY-zLMbn26H45Uye9bq1M4GSi05oS0n0SHx0T41aDZfq1z1QM3Gk2K9GdKDZAa0_LMkALKubHXniORjAS39U6cXtedLf44euUdohR5z5THj75vvAQYWt64TnqajOJHWgUIt8G1r1EXGWAEnPFXHTRLfPdHjfFNqeK73EQaXD0GzvBi1l6sitA2OeWHf7IKv8I1UmTtHUV1f27ij894DE2eG6LIZaRYa" } //PIn8TtqlNLnaA4DxTIzPNsqhGNXvDGuv06WR7Ki9PpumQH9UU39pU0bI5IzV27aA6mi2G7vsHpGgSpvWRGTGFG9a6MGME7uM3tiQLbaZVGqQ9XyjS7zMR64vJJKGQ2521WvKFX9AI5y34pSw469OOdeREny8Kq5DHmSg5GXsC5mQ3tW62saHGnuQQ2LmMGPKF35H1IL76avHJdmKEaeoDbuiBd0uSqWQN2WjJ0XPRXDVK2rIHpDi9GerT7zFKIea3IHIJdWcHZmH9Jn2KcTV87L78J0j4tSoKL0 //var token = appClient.getAccessToken(code).ToObject<ZaloToken>(); string access_token = "4KvSI2BvOYKGIbT4Albc9Xb9LKScupLH61PwRM3yINyr7H1pHQrZGZv8AJfhXtrVKt4tHY-zLMbn26H45Uye9bq1M4GSi05oS0n0SHx0T41aDZfq1z1QM3Gk2K9GdKDZAa0_LMkALKubHXniORjAS39U6cXtedLf44euUdohR5z5THj75vvAQYWt64TnqajOJHWgUIt8G1r1EXGWAEnPFXHTRLfPdHjfFNqeK73EQaXD0GzvBi1l6sitA2OeWHf7IKv8I1UmTtHUV1f27ij894DE2eG6LIZaRYa"; access_token = "PIn8TtqlNLnaA4DxTIzPNsqhGNXvDGuv06WR7Ki9PpumQH9UU39pU0bI5IzV27aA6mi2G7vsHpGgSpvWRGTGFG9a6MGME7uM3tiQLbaZVGqQ9XyjS7zMR64vJJKGQ2521WvKFX9AI5y34pSw469OOdeREny8Kq5DHmSg5GXsC5mQ3tW62saHGnuQQ2LmMGPKF35H1IL76avHJdmKEaeoDbuiBd0uSqWQN2WjJ0XPRXDVK2rIHpDi9GerT7zFKIea3IHIJdWcHZmH9Jn2KcTV87L78J0j4tSoKL0"; //access_token = token.access_token; string fields = "id, name, picture, gender, birthday"; var friends = appClient.getFriends(access_token, 0, int.MaxValue, fields).ToString(); //var invitable_friends = appClient.getInvitableFriends(access_token, 0, int.MaxValue, fields).ToString(); //var profile = appClient.getProfile(access_token, fields).ToString(); //var postFeed = appClient.postFeed(access_token, "hello world2!", "https://thinh.iot.vn/").ToString(); //FAIL: { "error": 12010, "message": "Quota daily per user for your app is limited" } //OK: {"id":"123123123_23123"} Console.WriteLine("Enter to exit ..."); Console.ReadKey(); }
public async Task <IActionResult> ZaloRegister([FromForm] ExternalUserLogin obj) { Zalo3rdAppInfo appInfo = new Zalo3rdAppInfo(Int64.Parse(_externalProvider.Value.Zalo.AppId), _externalProvider.Value.Zalo.SecretCode, _externalProvider.Value.Zalo.CallbackUrl); Zalo3rdAppClient appClient = new Zalo3rdAppClient(appInfo); JObject profile = appClient.getProfile(obj.AccessToken, "name, id, picture"); var tmpData = profile.ToObject <ExternalUserModel>(); var user = new ApplicationUser(); user.Email = obj.Email; user.UserName = "******" + tmpData.id; user.FullName = tmpData.name; user.PasswordHash = tmpData.id.ToString(); user.Avatar = tmpData.picture.data.url; return(await ExternalUser(user)); }
public ZaloUtils() { var info = new Zalo3rdAppInfo(long.Parse(ZALO_APP_ID), ZALO_APP_SECRET, ZALO_APP_CALLBACK); appClient = new Zalo3rdAppClient(info); }
public ApiResponse UpsertPersonalZalo() { ApiResponse response = new ApiResponse(); response.msg = "Add channel error"; try { var id_zalo_appid = Request.Cookies["id_zalo_appid"]; var id_zalo_channelid = Request.Cookies["id_zalo_channelid"]; var id_zalo_business_id = Request.Cookies["id_zalo_business_id"]; var id_zalo_appsecret = Request.Cookies["id_zalo_appsecret"]; var id_zalo_name = Request.Cookies["id_zalo_name"]; var id_zalo_templateid = Request.Cookies["id_zalo_templateid"]; var codeZalo = Request.Cookies["codeZalo"]; if (string.IsNullOrWhiteSpace(codeZalo) || string.IsNullOrWhiteSpace(id_zalo_business_id)) { return(response); } var appInfo = new Zalo3rdAppInfo(Convert.ToInt64(id_zalo_appid), id_zalo_appsecret, _appSettings.BaseUrls.Web + "zaloauth"); var appClient = new Zalo3rdAppClient(appInfo); JObject tokenObj = appClient.getAccessToken(codeZalo); var token = (string)tokenObj["access_token"]; if (token == null) { return(response); } var profile = appClient.getProfile(token, "id,name,birthday,gender,picture"); var profile_id = (string)profile["id"]; if (!string.IsNullOrWhiteSpace(profile_id)) { // upsert Channel para = new Channel(); para.business_id = id_zalo_business_id; para.ext_id = id_zalo_appid; para.name = id_zalo_name; para.id = id_zalo_channelid; para.template_id = id_zalo_templateid; para.token = token; para.type = "zalo_personal"; para.secret = id_zalo_appsecret; var rs1 = Core.Helpers.WebHelper.HttpPostAsync(_appSettings.BaseUrls.Api + "brands/zalos/upsert", para).Result; if (!rs1) { return(response); } // var rs1 = Core.Helpers.WebHelper.HttpPostAsync(_appSettings.BaseUrls.Api + "brands/zalos/upsert/zalo-personal/" + id_zalo_business_id + "/" + id_zalo_channelid + "/" + profile_id + "/" + token + "/" + id_zalo_name + "/" + id_zalo_templateid, null).Result; var access_token = Request.Cookies["access_token"] ?? ""; var url = _appSettings.BaseUrls.Api + "brands/channels/list/" + id_zalo_business_id + "/?access_token=" + access_token; var rs = Core.Helpers.WebHelper.HttpGetAsync <ChannelFeed>(url).Result; if (rs == null || rs.Data == null) { rs = new ChannelFeed { Data = new List <Channel>() } } ; var result = _viewRenderService.RenderToStringAsync("Channel/Settings", new ChannelSettings { business_id = id_zalo_business_id, Channels = rs.Data, ZaloAuth = "" }).Result; response.msg = "Add channel ok"; response.view = result; response.ok = true; Response.Cookies.Delete("id_zalo_appid"); Response.Cookies.Delete("id_zalo_channelid"); Response.Cookies.Delete("id_zalo_business_id"); Response.Cookies.Delete("id_zalo_appsecret"); Response.Cookies.Delete("id_zalo_name"); Response.Cookies.Delete("id_zalo_templateid"); Response.Cookies.Delete("codeZalo"); return(response); } return(response); } catch (Exception ex) { response.msg = "Add channel error " + ex.Message; response.ok = false; return(response); } }