//同步 protected void btnSyn_Click(object sender, EventArgs e) { string err = ""; Model.wx_userweixin weixin = GetWeiXinCode(); WeiXinCRMComm wcr = new WeiXinCRMComm(); string accessToken = wcr.getAccessToken(weixin.id, out err); if (err != "") { return; } GroupsJson gJson = Groups.Get(accessToken); List <GroupsJson_Group> gjg = gJson.groups; #region 将数据插入到数据库里 BLL.wx_crm_group gBll = new BLL.wx_crm_group(); Model.wx_crm_group group = new Model.wx_crm_group(); try { gBll.DeleteByWid(weixin.id); int ttCount = gjg.Count; int insertCount = 0; for (int i = 0; i < gjg.Count; i++) { group.id = gjg[i].id; group.name = gjg[i].name; group.count = gjg[i].count; group.wid = weixin.id; bool succ = gBll.Add(group); if (succ) { insertCount++; } } if (ttCount == insertCount) { //将此次同步的日期更新到设置表里 BLL.wx_crm_setting setBll = new BLL.wx_crm_setting(); setBll.UpdateGroupSysDate(weixin.id, ttCount, DateTime.Now); JscriptMsg("分组同步成功!", "group_list.aspx", "Success"); } else { JscriptMsg("分组同步失败!", "", "Error"); return; } } catch (Exception ex) { JscriptMsg("分组同步失败!" + ex.Message, "", "Error"); return; } #endregion }
/// <summary> /// 获取微信accessToken; /// </summary> /// <returns></returns> public string Token() { WeiXinCRMComm dd = new WeiXinCRMComm(); string error = ""; WeiXCommFun wxcomm = new WeiXCommFun(); string accessToken = dd.getAccessToken(wid(), out error); return(accessToken); }
public string stoce() { WeiXinCRMComm dd = new WeiXinCRMComm(); string error = ""; WeiXCommFun wxcomm = new WeiXCommFun(); int wid = 44; string sctokn = dd.getAccessToken(wid, out error); return(sctokn); }
public void SendTextTest(string openId) { Model.wx_userweixin weixin = GetWeiXinCode(); WeiXinCRMComm cpp = new WeiXinCRMComm(); string error = ""; string accessToken = cpp.getAccessToken(weixin.id, out error); var result = CustomApi.SendText(accessToken, openId, "sdfdsdf"); }
private string UploadForeverMedia(int wid, string mediaPath) { string err; var token = WeiXinCRMComm.getAccessToken(wid, out err); if (!string.IsNullOrEmpty(err)) { return(string.Empty); } var result = MediaApi.UploadForeverMedia(token, Server.MapPath(mediaPath)); return(result.media_id); }
/// <summary> /// 发货 /// </summary> /// <param name="paymentInfo"></param> /// <param name="orderEntity"></param> /// <returns></returns> public Dictionary <string, object> fahuomgr(Model.wx_payment_wxpay paymentInfo, Model.orders orderEntity) { BLL.wx_logs logBll = new BLL.wx_logs(); string funName = "发货"; logBll.AddLog(paymentInfo.wid.Value, "微支付", funName, "开始执行fahuomgr方法[otid:" + orderEntity.id + "]"); WxPayHelper wxPayHelper = new WxPayHelper(); wx_payment_wxpay payBll = new wx_payment_wxpay(); //先设置基本信息 string partnerId = paymentInfo.partnerId; //"1218574001"; string appId = paymentInfo.appId; // "wxa9b8e33e48ac5e0f"; string partnerKey = paymentInfo.partnerKey; // "huyuxianghuyuxianghuyuxiang12345"; //paysignkey(非appkey) string appKey = paymentInfo.paySignKey; // "nwRmqgvSG08pe3vU5qzBLb7Bvih0WOABGzUPvqgFqE0iSkJlJ8wh7JlLYy2cXFgFA3v1bM8eTDm1y1UcyeW9IGq2py2qei7J5xDoVR9lfO3cS6fMjFbMQeeqBRit0bKp"; wxPayHelper.SetAppId(appId); wxPayHelper.SetAppKey(appKey); wxPayHelper.SetPartnerKey(partnerKey); wxPayHelper.SetSignType("sha1"); //设置请求package信息 WeiXinCRMComm wxComm = new WeiXinCRMComm(); string err = ""; string access_token = wxComm.getAccessToken(paymentInfo.wid.Value, out err); string param = wxPayHelper.CreateFaHuoPackage(orderEntity.openid, orderEntity.trade_no, orderEntity.order_no); string url = "https://api.weixin.qq.com/pay/delivernotify?access_token=" + access_token; string ret = Utils.HttpPost(url, param); logBll.AddLog(paymentInfo.wid.Value, "微支付", funName, "ret=" + ret); Dictionary <string, object> dict = JsonToDictionary(ret); logBll.AddLog(paymentInfo.wid.Value, "微支付", funName, "[otid:" + orderEntity.id + "]发货成功"); //string errcode = dict["errcode"].ToString(); //string errmsg = dict["errmsg"].ToString(); //mxAuthFrame.BLL.wxOrderTmpBLL wot = new mxAuthFrame.BLL.wxOrderTmpBLL(); //ordertmp.fahuoCode = errcode; //ordertmp.fahuoMsg = errmsg; //wot.Update(ordertmp); //Dictionary<string, string> ret_d = new Dictionary<string, string>(); //ret_d.Add(errcode, errmsg); return(dict); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { openid = MyCommFun.RequestOpenid(); otid = MyCommFun.RequestInt("otid"); int wid = MyCommFun.RequestWid(); if (openid == "" || otid == 0 || wid == 0) { return; } WeiXinCRMComm wxComm = new WeiXinCRMComm(); string err = ""; token = wxComm.getAccessToken(wid, out err); BLL.orders otBll = new BLL.orders(); ordertmp = otBll.GetModel(otid, wid); } }
protected void FlushAT_Click(object sender, EventArgs e) { try { Model.wx_userweixin weixin = GetWeiXinCode(); string error = ""; WeiXinCRMComm.FlushAccessToken(weixin.id, out error); if (error != "") { JscriptMsg(error, "", "Error"); return; } JscriptMsg("Access_Token更新成功!", "wxMenu.aspx", "Success"); } catch (Exception ex) { JscriptMsg("执行过程出现错误:" + ex.Message, "back", "Error"); return; } }
/// <summary> ///同步按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSyn_Click(object sender, EventArgs e) { string err = ""; Model.wx_userweixin weixin = GetWeiXinCode(); WeiXinCRMComm wcr = new WeiXinCRMComm(); string accessToken = wcr.getAccessToken(weixin.id, out err); if (err != "") { return; } BLL.wx_crm_users uBll = new BLL.wx_crm_users(); //更新时间,作为一个标记 DateTime updateTime = DateTime.Now; try { string ret = SysPersonFun(0, weixin.id, accessToken, "", updateTime); //查找此次为同步到的,则为已经跑路的 IList <Model.wx_crm_users> userlist = uBll.GetModelList("updateDate<'" + updateTime.ToString() + "'"); if (userlist != null && userlist.Count > 0) { for (int i = 0; i < userlist.Count; i++) { userlist[i].uStatus = 2; uBll.Update(userlist[i]); } } JscriptMsg(ret, "user_list.aspx", "Success"); } catch (Exception ex) { lblInfo.Text = ex.Message; } }
public void WeChatConfigInit(int wid, string url) { try { string errorString; var ticket = WeiXinCRMComm.getJsApiTicket(wid, out errorString); if (!string.IsNullOrEmpty(errorString)) { HttpContext.Current.Response.Write(AjaxResult.Error(errorString)); } else { var wxModel = new BLL.wx_userweixin().GetModel(wid); if (wxModel == null) { HttpContext.Current.Response.Write(AjaxResult.Error("不合法的参数wid")); return; } var noncestr = JSSDKHelper.GetNoncestr(); var timestamp = JSSDKHelper.GetTimestamp(); var singature = new JSSDKHelper().GetSignature(ticket, noncestr, timestamp, url); var result = new { appId = wxModel.AppId, timestamp = timestamp, nonceStr = noncestr, signature = singature }; HttpContext.Current.Response.Write(AjaxResult.Success(result)); } } catch (Exception exception) { HttpContext.Current.Response.Write(AjaxResult.Error(exception.Message)); } }
/// <summary> /// 删当前菜单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnDelMenu_Click(object sender, EventArgs e) { try { Model.wx_userweixin weixin = GetWeiXinCode(); string error = ""; string token = WeiXinCRMComm.getAccessToken(weixin.id, out error); if (error != "") { JscriptMsg(error, "", "Error"); return; } var result = OneGulp.WeChat.MP.CommonAPIs.CommonApi.DeleteMenu(token); //重新获得最新的菜单 GetMenu(); } catch (Exception ex) { JscriptMsg("执行过程出现错误:" + ex.Message, "back", "Error"); return; } }
private void GetMenu() { try { Model.wx_userweixin weixin = GetWeiXinCode(); string error = ""; string accessToken = WeiXinCRMComm.getAccessToken(weixin.id, out error); if (error != "") { JscriptMsg(error, "", "Error"); return; } GetMenuResult result = mMrg.GetMenu(accessToken); if (result == null) { //JscriptMsg("未获得到菜单,请参考【使用规则】,自行排查问题!", "", "Error"); return; //强制刷新 //accessToken = cpp.FlushAccessToken(weixin.id, out error); //result = CommonApi.GetMenu(accessToken); } var topButtonList = result.menu.button; int topNum = topButtonList.Count; TextBox txtName = new TextBox(); TextBox txtKey = new TextBox(); TextBox txtUrl = new TextBox(); for (int i = 0; i < topNum; i++) { var topButton = topButtonList[i]; if (topButton != null) { txtName = this.FindControl("txtTop" + (i + 1)) as TextBox; txtKey = this.FindControl("txtTop" + (i + 1) + "Key") as TextBox; txtUrl = this.FindControl("txtTop" + (i + 1) + "Url") as TextBox; txtName.Text = topButton.name; if (topButton.GetType() != typeof(SubButton)) { //下面无子菜单 if (topButton.GetType() == typeof(SingleViewButton)) { //view 页面跳转 txtUrl.Text = ((SingleViewButton)topButton).url; } else { txtKey.Text = ((SingleClickButton)topButton).key; } } else { //下面有子菜单 IList <SingleButton> subButtonList = ((SubButton)topButton).sub_button; if (subButtonList != null && subButtonList.Count > 0) { TextBox txtSubName = new TextBox(); TextBox txtSubKey = new TextBox(); TextBox txtSubUrl = new TextBox(); for (int j = 0; j < subButtonList.Count; j++) { txtSubName = this.FindControl("txtMenu" + (i + 1) + (j + 1)) as TextBox; txtSubKey = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Key") as TextBox; txtSubUrl = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Url") as TextBox; if (subButtonList[j].GetType() == typeof(SingleViewButton)) { SingleViewButton sub = (SingleViewButton)subButtonList[j]; txtSubName.Text = sub.name; txtSubUrl.Text = sub.url; } else { SingleClickButton sub = (SingleClickButton)subButtonList[j]; txtSubName.Text = sub.name; txtSubKey.Text = sub.key; } } } } } } } catch (Exception ex) { } }
/// <summary> /// 更新菜单 /// </summary> protected void btnSubmit_Click(object sender, EventArgs e) { try { Model.wx_userweixin weixin = GetWeiXinCode(); string error = ""; string accessToken = WeiXinCRMComm.getAccessToken(weixin.id, out error); if (error != "") { JscriptMsg(error, "", "Error"); return; } //重新整理按钮信息 ButtonGroup bg = new ButtonGroup(); TextBox txtName = new TextBox(); TextBox txtKey = new TextBox(); TextBox txtUrl = new TextBox(); IList <BaseButton> topList = new List <BaseButton>(); IList <SingleButton> subList = new List <SingleButton>(); #region 菜单设置 for (int i = 0; i < 3; i++) { txtName = this.FindControl("txtTop" + (i + 1)) as TextBox; txtKey = this.FindControl("txtTop" + (i + 1) + "Key") as TextBox; txtUrl = this.FindControl("txtTop" + (i + 1) + "Url") as TextBox; if (txtName.Text.Trim() == "") { // 如果名称为空,则忽略该菜单,以及下面的子菜单 continue; } subList = new List <SingleButton>(); TextBox txtSubName = new TextBox(); TextBox txtSubKey = new TextBox(); TextBox txtSubUrl = new TextBox(); for (int j = 0; j < 5; j++) { #region 子菜单的设置 txtSubName = this.FindControl("txtMenu" + (i + 1) + (j + 1)) as TextBox; txtSubKey = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Key") as TextBox; txtSubUrl = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Url") as TextBox; if (txtSubName.Text.Trim() == "") { continue; } if (txtSubUrl.Text.Trim() != "") { SingleViewButton sub = new SingleViewButton(); sub.name = txtSubName.Text.Trim(); sub.url = txtSubUrl.Text.Trim(); subList.Add(sub); } else if (txtSubKey.Text.Trim() != "") { SingleClickButton sub = new SingleClickButton(); sub.name = txtSubName.Text.Trim(); sub.key = txtSubKey.Text.Trim(); subList.Add(sub); } else { //报错 :子菜单必须有key和name JscriptMsg("二级菜单的名称和key或者url必填!", "", "Error"); return; } #endregion } //子菜单循环结束 if (subList != null && subList.Count > 0) { //有子菜单, 该一级菜单是SubButton if (subList.Count < 1) { JscriptMsg("子菜单个数为2~5个!", "", "Error"); return; } SubButton topButton = new SubButton(Utils.CutString(txtName.Text.Trim(), 16)); topButton.sub_button.AddRange(subList); topList.Add(topButton); } else { // 无子菜单 if (txtKey.Text.Trim() == "" && txtUrl.Text.Trim() == "") { JscriptMsg("若无子菜单,必须填写key或者url值!", "", "Error"); return; } if (txtUrl.Text.Trim() != "") { //view 页面跳转 SingleViewButton topSingleButton = new SingleViewButton(); topSingleButton.name = txtName.Text.Trim(); topSingleButton.url = txtUrl.Text.Trim(); topList.Add(topSingleButton); } else if (txtKey.Text.Trim() != "") { SingleClickButton topSingleButton = new SingleClickButton(); topSingleButton.name = txtName.Text.Trim(); topSingleButton.key = txtKey.Text.Trim(); topList.Add(topSingleButton); } } } #endregion bg.button.AddRange(topList); var result = mMrg.CreateMenu(accessToken, bg); JscriptMsg("菜单提交成功!", "wxMenu.aspx", "Success"); } catch (Exception ex) { JscriptMsg("报错:" + ex.Message, "", "Error"); } }
protected void btnSendout_Click(object sender, EventArgs e) { BLL.wx_crm_fodder cfBll = new BLL.wx_crm_fodder(); Model.wx_userweixin weixin = GetWeiXinCode(); //当前微信用户 Model.wx_crm_users cuModel = cuBll.GetModel(uid); //当前粉丝 string error = ""; string accessToken = WeiXinCRMComm.getAccessToken(weixin.id, out error); Model.wx_response_BaseData rc = new Model.wx_response_BaseData(); try { rc.createDate = DateTime.Now; rc.wid = weixin.id; rc.flag = 1; rc.rType = "客服回复"; rc.wx_openid = cuModel.openid;//当前粉丝的openid if (rblResponseType.SelectedItem.Value == "0") { //纯文本 //规则 if (this.txtContent.Text.Trim().Length == 0) { JscriptMsg("内容不能为空", "back", "Error"); return; } //添加内容 rc.reponseContent = txtContent.Text.Trim(); rc.responseType = "text"; SendText(accessToken, cuModel.openid, txtContent.Text.Trim()); } else if (rblResponseType.SelectedItem.Value == "1") { #region 图文的信息回复 //图文 //判断图片来自服务器或公网 string imgurl = this.txtImgUrl.Text; if (imgurl.IndexOf("http") < 0) { imgurl = MyCommFun.getWebSite() + imgurl; } //发送图文 List <Article> artList = new List <Article> { new Article() { Url = this.txtUrl.Text, PicUrl = imgurl, Title = this.txtTitle.Text, Description = this.txtNewsContent.Value }, }; SendNews(accessToken, cuModel.openid, artList); //添加内容 Model.wx_crm_fodder cfModel = new Model.wx_crm_fodder { scContent = this.txtNewsContent.Value, title = this.txtTitle.Text, picurl = imgurl, url = this.txtUrl.Text, createDate = DateTime.Now }; int res = cfBll.Add(cfModel); Dictionary <string, string> jsonDict = new Dictionary <string, string>(); jsonDict.Add("title", this.txtTitle.Text); jsonDict.Add("scContent", this.txtNewsContent.Value); jsonDict.Add("picurl", imgurl); jsonDict.Add("url", this.txtUrl.Text); jsonDict.Add("createDate", this.txtUrl.Text); rc.reponseContent = this.txtTitle.Text + ""; rc.responseType = "news"; #endregion } else if (rblResponseType.SelectedItem.Value == "2") { //语音 if (this.txtMusicTitle.Text.Trim().Length == 0) { JscriptMsg("音乐不能为空", "back", "Error"); return; } if (this.txtMusicFile.Text.Trim().Length == 0) { JscriptMsg("音乐链接不能为空", "back", "Error"); return; } //添加内容 rc.responseType = "voice"; rc.remark = txtMusicRemark.Text; SendVoice(accessToken, cuModel.openid, "Media_Id"); } rcBll.Add(rc); //AddAdminLog(MXEnums.ActionEnum.Edit.ToString(), "编辑" + ruleName); //记录日志 JscriptMsg("发送信息成功!", "talk.aspx?keywords=" + this.keywords + "&id=" + uid, "Success"); } catch (Exception) { JscriptMsg("发送信息失败!", "talk.aspx?keywords=" + this.keywords + "&id=" + uid, "Error"); return; } }
/// <summary> /// 保存配置信息 /// </summary> protected void btnSubmit_Click(object sender, EventArgs e) { //ChkAdminLevel("site_config", MXEnums.ActionEnum.Edit.ToString()); //检查权限 string ruleName = ""; try { //保存之前,删除以前的数据 int requestType = int.Parse(lblreqestType.Text);//请求的类别 if (requestType == 6) { ruleName = "关注时的触发内容"; } else if (requestType == 0) { ruleName = "默认回复内容"; } else if (requestType == 7) { ruleName = "取消关注时的触发内容"; } Model.manager manager = GetAdminInfo(); Model.wx_userweixin weixin = GetWeiXinCode(); //添加前删除原来的数据 rBll.DeleteRule(int.Parse(hidId.Value)); Model.wx_requestRule rule = new Model.wx_requestRule(); rule.uId = manager.id; rule.wId = weixin.id; rule.ruleName = ruleName; rule.reqestType = requestType; rule.isDefault = false; rule.createDate = DateTime.Now; Model.wx_requestRuleContent rc = new Model.wx_requestRuleContent(); if (rblResponseType.SelectedItem.Value == "0") { //纯文本 //规则 if (this.txtContent.Text.Trim().Length == 0) { JscriptMsg("内容不能为空", "back", "Error"); return; } rule.responseType = 1;//回复的类型:文本1,图文2,语音3,视频4,第三方接口5 int rId = rBll.Add(rule); //内容 rc.rId = rId; rc.uId = manager.id; rc.rContent = txtContent.Text.Trim(); rc.createDate = DateTime.Now; rcBll.Add(rc); } else if (rblResponseType.SelectedItem.Value == "1") { //图文 rule.responseType = 2; //回复的类型:文本1,图文2,语音3,视频4,第三方接口5 int rId = rBll.Add(rule); } else if (rblResponseType.SelectedItem.Value == "2") { //语音 if (this.txtMusicTitle.Text.Trim().Length == 0) { JscriptMsg("音乐不能为空", "back", "Error"); return; } if (this.txtMusicFile.Text.Trim().Length == 0) { JscriptMsg("音乐链接不能为空", "back", "Error"); return; } //规则 rule.responseType = 3;//回复的类型:文本1,图文2,语音3,视频4,第三方接口5 int rId = rBll.Add(rule); //Modify by Yidane //语音先上传微信服务器,获取到media_id,保存到数据库 if (File.Exists(Server.MapPath(txtMusicFile.Text))) { try { var err = string.Empty; var token = WeiXinCRMComm.getAccessToken(weixin.id, out err); if (string.IsNullOrEmpty(err)) { var result = MediaApi.UploadForeverMedia(token, Server.MapPath(txtMusicFile.Text)); rc.extStr = result.media_id; } } catch (Exception) { } } //内容 rc.rId = rId; rc.uId = manager.id; rc.createDate = DateTime.Now; rc.mediaUrl = txtMusicFile.Text; rc.rContent = txtMusicTitle.Text; rc.remark = txtMusicRemark.Text; rcBll.Add(rc); if (string.IsNullOrEmpty(rc.extStr)) { JscriptMsg("编辑" + ruleName + "有问题!", "subscribe.aspx?act=" + MyCommFun.QueryString("act"), "Error"); } } AddAdminLog(MXEnums.ActionEnum.Edit.ToString(), "编辑" + ruleName); //记录日志 JscriptMsg("编辑" + ruleName + "成功!", "subscribe.aspx?act=" + MyCommFun.QueryString("act"), "Success"); } catch { JscriptMsg("编辑" + ruleName + "有问题!", "subscribe.aspx?act=" + MyCommFun.QueryString("act"), "Error"); } }