diff --git a/TEMUKJD/BLL/HttpResponseWxAiTalkBLL.cs b/TEMUKJD/BLL/HttpResponseWxAiTalkBLL.cs index 2310faf..8b47695 100644 --- a/TEMUKJD/BLL/HttpResponseWxAiTalkBLL.cs +++ b/TEMUKJD/BLL/HttpResponseWxAiTalkBLL.cs @@ -93,6 +93,7 @@ namespace TemuKJD.BLL HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.KeepAlive = true; + request.Timeout = 1000 * 45; request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"; request.ContentType = "application/json"; request.Accept = "*/*"; diff --git a/TEMUKJD/WXForms/AiTalkForms/WxAiTalkForm.cs b/TEMUKJD/WXForms/AiTalkForms/WxAiTalkForm.cs index 3f1de54..baf8a6b 100644 --- a/TEMUKJD/WXForms/AiTalkForms/WxAiTalkForm.cs +++ b/TEMUKJD/WXForms/AiTalkForms/WxAiTalkForm.cs @@ -849,7 +849,7 @@ namespace TemuKJD.WXForms.AiTalkForms } } - private void Lf_SaveComplete(object o_shop, object o_appSecret, object o_wxShopLoginForm) + private async void Lf_SaveComplete(object o_shop, object o_appSecret, object o_wxShopLoginForm) { if (o_shop is ShopLoginInfo shop && o_wxShopLoginForm is WXShopLoginForm shopLoginFrom) { @@ -866,24 +866,38 @@ namespace TemuKJD.WXForms.AiTalkForms string body = @"{""id"":""" + appId + @""",""appId"":""" + appId + @""",""name"":""" + shop.ShopAccount + @""",""apiKey"":""" + appSecret + @""",""secret"":""" + appSecret + @""",""token"":""" + appId + @""",""encodingAesKey"":""" + aesKey + @""",""callbackUrl"":""" + callbackUrl + @"""}"; - string url = AiTalkUrl + "/api/stores"; + string url = AiTalkUrl + "/api/stores/upsert"; string refer = AiTalkUrl + "/workbanch"; var cookies = CEFBrowser.GetCookieList("", aiTalkAdminWebBrowser.RequestContext.GetCookieManager(null)); - var rst = HttpResponseWxAiTalkBLL.PostResponse(new ShopLoginInfo() { Cookies = JsonHelper.SerializeObject(cookies) }, url, body, refer); - if (!rst.Contains("\"id\":\"" + appId + "\"")) + string rst = ""; + await Task.Run(() => + { + rst = HttpResponseWxAiTalkBLL.PostResponse(new ShopLoginInfo() { Cookies = JsonHelper.SerializeObject(cookies) }, url, body, refer); + }); + if (!rst.Contains("\"id\":\"" + appId + "\"")) { shopLoginFrom.lblSecret.Text = "接入Ai客服错误!请重试!"; return; } - // 拿到密钥去微信小店开通消息推送 - url = "https://store.weixin.qq.com/shop-faas/mmecnodeservicemarket/channel/ChannelsEcVerifyCallbackInfo?token=&lang=zh_CN"; - refer = "https://store.weixin.qq.com/shop/servicemarket/home"; - //{"url":"http://14.103.99.254/wechat/wx316b1291351558aa/callback","token":"wx316b1291351558aa","base64Key":"PZPtKsJ165j3IE1YOe0mxJLwiq125lES2Lq2xplg3KU"} - body = "{\"url\":\"" + callbackUrl + "\",\"token\":\"" + appId + "\",\"base64Key\":\"" + aesKey + "\"}"; - rst = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refer); - //{"ret":0,"success":true,"code":0} - if (!rst.Contains("\"code\":0")) + await Task.Run(() => + { + // 拿到密钥去微信小店开通消息推送 + url = "https://store.weixin.qq.com/shop-faas/mmecnodeservicemarket/channel/ChannelsEcVerifyCallbackInfo?token=&lang=zh_CN"; + refer = "https://store.weixin.qq.com/shop/servicemarket/home"; + //{"url":"http://14.103.99.254/wechat/wx316b1291351558aa/callback","token":"wx316b1291351558aa","base64Key":"PZPtKsJ165j3IE1YOe0mxJLwiq125lES2Lq2xplg3KU"} + body = "{\"url\":\"" + callbackUrl + "\",\"token\":\"" + appId + "\",\"base64Key\":\"" + aesKey + "\"}"; + Thread.Sleep(Randomx.GetId(250, 500)); + rst = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refer); + if (!rst.Contains("\"code\":0")) + { + Thread.Sleep(Randomx.GetId(500, 1000)); + rst = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refer); + } + }); + + //{"ret":0,"success":true,"code":0} + if (!rst.Contains("\"code\":0")) { WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false); if (shop.LoginStatus != "登录成功") @@ -899,7 +913,7 @@ namespace TemuKJD.WXForms.AiTalkForms shopLoginFrom.lblSecret.Text = "请点击客服设置,接入自研客服,扫码接入(不接入接收不到消息)"; shopLoginFrom.btnSaveAppSecret.Text = "我已接入,关闭窗口"; - Task.Run(() => + await Task.Run(() => { Thread.Sleep(500); BatchBindShop(new List { shop.ShopId });