protected string GetTextCardPushJson(bool OAuth2, PushParamModel pushMsg) { var agentid = SyntacticSugar.ConfigSugar.GetAppString("WeChatAgentID", "1"); string _oAuthUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_base#wechat_redirect"; string responeJsonStr = ""; responeJsonStr = "{"; responeJsonStr += "\"touser\": \"" + pushMsg.PushPeoples + "\","; responeJsonStr += "\"toparty\": \"\","; responeJsonStr += "\"totag\": \"\","; responeJsonStr += "\"msgtype\": \"textcard\","; responeJsonStr += "\"agentid\":\"" + agentid + "\","; responeJsonStr += "\"textcard\": {"; string pushUrl = string.Empty; if (OAuth2) { pushUrl = string.Format(_oAuthUrl, WxPayConfig.APPID, pushMsg.Url); } else { pushUrl = pushMsg.Url; } responeJsonStr += "\"title\": \"" + pushMsg.Title + "\","; responeJsonStr += "\"description\": \"" + pushMsg.Message + "\","; responeJsonStr += "\"url\": \"" + pushUrl + "\","; //responeJsonStr += "\"picurl\": \"" + pushMsg.Image + "\""; responeJsonStr += "\"btntxt\": \"更多\""; responeJsonStr += "}"; responeJsonStr += "}"; return(responeJsonStr); }
private string GetTextPushJson(PushParamModel pushMsg) { var agentid = SyntacticSugar.ConfigSugar.GetAppString("WeChatAgentID", "1"); string responeJsonStr = ""; responeJsonStr = "{"; responeJsonStr += "\"touser\": \"" + pushMsg.PushPeoples + "\","; responeJsonStr += "\"toparty\": \"\","; responeJsonStr += "\"totag\": \"\","; responeJsonStr += "\"msgtype\": \"text\","; responeJsonStr += "\"agentid\":\"" + agentid + "\","; responeJsonStr += "\"text\": {\"content\" : \"" + pushMsg.Message + "\"},"; responeJsonStr += "\"safe\": \"0\","; responeJsonStr += "\"enable_id_trans\": \"0\","; responeJsonStr += "\"enable_duplicate_check\": \"0\","; responeJsonStr += "\"duplicate_check_interval\": \"1800\""; responeJsonStr += "}"; return(responeJsonStr); }
public JsonResult WXTextPush(string SECURITYKEY, string pushparam) { ExecutionResult result = new ExecutionResult(); try { if (API_Authentication(SECURITYKEY)) { PushParamModel textPush = Extend.JsonToModel <PushParamModel>(pushparam); var textPushs = new List <PushParamModel> { textPush }; //result = SaveGraphicPushData(textPushs); string accessToken = Common.WeChatPush.WeChatTools.GetAccessoken(); string _sendUrl = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={0}"; string postUrl = string.Format(_sendUrl, accessToken); //获取推送内容Json string json = GetTextPushJson(textPush); string pushResult = WeChatTools.PostWebRequest(postUrl, json, Encoding.UTF8); var wechatResult = Extend.JsonToModel <U_WechatResult>(pushResult); if (wechatResult.errcode == "0") { result.Success = true; } result.Message = pushResult; } else { result.Message = "SECURITYKEY 无效!"; } } catch (Exception ex) { result.Message = ex.Message; LogHelper.WriteLog(ex.Message); } ExecHistry("WeChatTextPush", pushparam, JsonHelper.ModelToJson(result)); return(Json(result)); }
public JsonResult TextPush(string SECURITYKEY, string pushparam) { ExecutionResult result = new ExecutionResult(); try { if (API_Authentication(SECURITYKEY)) { PushParamModel textPush = Extend.JsonToModel <PushParamModel>(pushparam); U_PushMsg pushMsg = new U_PushMsg(); pushMsg.VGUID = Guid.NewGuid(); pushMsg.PushType = 1; pushMsg.MessageType = 1; pushMsg.Title = textPush.Title; pushMsg.Message = textPush.Message; pushMsg.PushPeople = textPush.founder; pushMsg.CreatedUser = "******"; pushMsg.CreatedDate = DateTime.Now; pushMsg.PeriodOfValidity = DateTime.Now.AddMonths(1); UserInfoLogic userInfoLogic = new UserInfoLogic(); if (textPush.PushPeople.Count == 0) { result.Message = "推送人员不能为空!"; ExecHistry("TextPush", pushparam, JsonHelper.ModelToJson(result)); return(Json(result)); } foreach (string item in textPush.PushPeople) { var user = userInfoLogic.GetPerson(item); if (user != null && user.UserID != null && user.UserID != "") { pushMsg.PushPeople += user.UserID + "|"; pushMsg.PushObject += user.UserID + "|"; } else { result.Message += item + "|"; } } if (!string.IsNullOrEmpty(result.Message)) { result.Message = result.Message.Remove(result.Message.Length - 1, 1); result.Message = "不存在身份证号码:" + result.Message; ExecHistry("TextPush", pushparam, JsonHelper.ModelToJson(result)); return(Json(result)); } DraftInfoLogic logic = new DraftInfoLogic(); Guid vguid = Guid.Empty; result.Success = logic.APISavePushMsg(pushMsg); result.Result = new { Uniquekey = pushMsg.VGUID }; } else { result.Message = "SECURITYKEY 无效!"; } } catch (Exception ex) { result.Message = ex.Message; LogHelper.WriteLog(ex.Message); } ExecHistry("TextPush", pushparam, JsonHelper.ModelToJson(result)); return(Json(result)); }