private void SendMsgZalo() { ZaloAppInfo appInfo = new ZaloAppInfo(4287047223436224874, "L1XL26QSnY2U6MWH850R", "http://test.net"); ZaloAppClient appClient = new ZaloAppClient(appInfo); string loginUrl = appClient.getLoginUrl(); //Process.Start(loginUrl); string code = "0FZeCRokLqeEykuokAHJJ0Jpwp2qiZu1VPhX0Q6jFtjAZy0BcgSB8KQhlZYKzsG1NEwxVfFNHLzuseDFbln9Qb_WgagJuXLC9hkhLTBcNdzk-8DWgVfvKMlWksZUrm5h5FkXOAJVV4jtmQ5fgVX2Jnpddr3Ym6TXBFdJHDtVQ3Wsv8CcuR9CALUxWWUIi5u198pdCEopMYa1jkKZiBm3B5QhvHRggGOGDAV9A_6NV3GtjBelsfm44MkZtmsyY2SeMQx7BQktEn1awlarsTCYJM64Rur8jxbNJ0"; JObject token = appClient.getAccessToken(code); var access_token = token["access_token"].ToString(); //JObject profile = appClient.getProfile(access_token, "id, name, birthday"); JObject friends = appClient.getFriends(access_token, 0, 100, "id, name, picture"); JObject sendMessage = appClient.sendMessage(access_token, 3852331461584449386, "test", ""); }
public ActionResult ZaloCallback(string accesstoken) { try { var appId = 3722523456944291775; var appSecret = "MU1RP7QQ6k8ndjhPNqdj"; if (!string.IsNullOrEmpty(accesstoken)) { ZaloAppInfo appInfo = new ZaloAppInfo(appId, appSecret, "callbackUrl"); ZaloAppClient appClient = new ZaloAppClient(appInfo); JObject me = appClient.getProfile(accesstoken, "fields=a,name,id,birthday,gender,phone,picture"); var output = JsonConvert.SerializeObject(me); ZaloCustomerItem deserializedProduct = JsonConvert.DeserializeObject <ZaloCustomerItem>(output); if (string.IsNullOrEmpty(deserializedProduct.error)) { var cus = new Base.Customer { UserName = deserializedProduct.name, FullName = deserializedProduct.name, DateCreated = DateTime.Now.TotalSeconds(), IsActive = true, IsDelete = false, idUserZalo = deserializedProduct.id, AvatarUrl = deserializedProduct.picture.data.url, }; InsertCustomerZalo(cus); var customer = customerDA.GetbyidUserZalo(cus.idUserZalo); var key = Guid.NewGuid(); IAuthContainerModel model = new JWTContainerModel() { Claims = new Claim[] { new Claim(type: "Phone", value: customer.Mobile ?? ""), new Claim(type: "Type", value: "Token"), new Claim(type: "ID", value: customer.ID.ToString()), }, ExpireMinutes = 10, }; IAuthContainerModel modelRefreshToken = new JWTContainerModel() { Claims = new Claim[] { new Claim(type: "Phone", value: customer.Mobile ?? ""), new Claim(type: "Type", value: "RefreshToken"), new Claim(type: "key", value: key.ToString()), new Claim(type: "ID", value: customer.ID.ToString()), }, ExpireMinutes = 60 * 24 * 30, }; var tokenResponse = JWTService.Instance.GenerateToken(model: model); var refreshToken = JWTService.Instance.GenerateToken(model: modelRefreshToken); customerDA.InsertToken(data: new TokenRefresh() { GuidId = key }); customerDA.Save(); return(Json(data: new BaseResponse <CustomerAppIG4Item>() { Code = 200, Erros = false, Message = "", Data = new CustomerAppIG4Item() { Token = tokenResponse, RefreshToken = refreshToken, ID = customer.ID } }, behavior: JsonRequestBehavior.AllowGet)); } return(Json(data: new { Code = deserializedProduct.error, Erros = true, Message = "Có lỗi xảy ra vui lòng xem lại mã lỗi" }, behavior: JsonRequestBehavior.AllowGet)); } } catch (Exception e) { return(Redirect("/")); } return(Redirect("/")); }
public Zalo3rdAppClient(ZaloAppInfo _appInfo) { this._appInfo = _appInfo; }