/// <summary> /// 获取二维码 /// </summary> /// <param name="scene_id"></param> /// <param name="count"></param> /// <returns></returns> public ResQRcode GetQRcode(int scene_id, string AppID = "", int count = 3) { Config config = getConfig(AppID); ResQRcode qr = new ResQRcode(); string str = "{\"expire_seconds\": 2592000, \"action_name\": \"QR_SCENE\", \"action_info\": {\"scene\": {\"scene_id\": " + scene_id + "}}}"; string res = ""; do { try { res = HttpWebResponseUtility.CreatePostDataResponse(Const.qrcode + config.accessToken, str); qr = JsonConvert.DeserializeObject <ResQRcode>(res); if (CheckSuccess(qr.errcode)) { count = 0; } } catch (Exception) { config = getConfig(AppID, true); } } while (count-- > 0); return(qr); }
/// <summary> /// 发送客服消息 /// </summary> /// <param name="message"></param> public BaseModel sendCustomMessage(CustomMessage message, string AppID = "", int count = 3) { Config config = getConfig(AppID); BaseModel baseModel = new BaseModel(); do { string res = ""; res = HttpWebResponseUtility.CreatePostDataResponse(Const.custom_message + config.accessToken, JsonConvert.SerializeObject(message)); log.Info("发送客服消息返回:" + res); try { baseModel = JsonConvert.DeserializeObject <BaseModel>(res); if (CheckSuccess(baseModel.errcode)) { count = 0; } } catch (Exception) { config = getConfig(AppID, true); } } while (count-- > 0); return(baseModel); }
/// <summary> /// 创建菜单 /// </summary> /// <param name="menu"></param> /// <returns></returns> public string CreateMenu(MenuModal menu, string AppID = "", int count = 3) { Config config = getConfig(AppID); string res = ""; do { try { res = HttpWebResponseUtility.CreatePostDataResponse(Const.menu_create + config.accessToken, JsonConvert.SerializeObject(menu)); count = 0; } catch (Exception ex) { config = getConfig(AppID, true); } }while (count-- > 0); return(res); }
/// <summary> /// 发送模板消息 /// </summary> /// <param name="message"></param> public ResTemplateMessageModel sendTemplateMessage(object obj, string AppID = "", int count = 3) { Config config = getConfig(AppID); ResTemplateMessageModel templateMessageModel = new ResTemplateMessageModel(); string res = ""; do { try { res = HttpWebResponseUtility.CreatePostDataResponse(Const.template_message + config.accessToken, JsonConvert.SerializeObject(obj)); templateMessageModel = JsonConvert.DeserializeObject <ResTemplateMessageModel>(res); if (CheckSuccess(templateMessageModel.errcode)) { count = 0; } } catch (Exception) { config = getConfig(AppID, true); } } while (count-- > 0); return(templateMessageModel); }