/// <summary> /// 关注时候处理 /// </summary> public string weipaiSubscribe(string openid, int wid) { BLL.wx_userweixin uwbll = new BLL.wx_userweixin(); string wxId = uwbll.GetwxId(wid);//原始Id if (wxId == null || wxId.Trim() == "") { return("wid参数错误"); } try { WeiXinPF.BLL.wx_paizhao_setting setBll = new WeiXinPF.BLL.wx_paizhao_setting(); WeiXinPF.Model.wx_paizhao_setting model = setBll.GetModelByWid(wid); if (model == null || model.isOpen == false) { return("未开启"); } Dictionary <string, string> parameters = new Dictionary <string, string>(); string url = model.initApiUrl;// "http://wphoto.betterwood.com:8080/Server/wechat/userinit.action"; string userid = openid; string sourceid = wxId;// "gh_e2d7eb82cb50"; 该用户的来源,即关注的哪一个微信公众账号)、(微信号)原始ID string timestamp = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString(); string v = "2000"; string signature = ""; parameters.Add("userid", openid); parameters.Add("sourceid", sourceid); parameters.Add("v", "2000"); parameters.Add("timestamp", timestamp); signature = GetBizSign(parameters); string postParam = "userid=" + userid + "&sourceid=" + sourceid + "×tamp=" + timestamp + "&v=" + v + "&signature=" + signature; string ret = Utils.HttpPost(url, postParam); Dictionary <string, object> dict = MyCommFun.JsonToDictionary(ret); string returnCode = dict["returncode"].ToString(); if (returnCode == "200") { //成功 WXLogs.AddLog(wid, "微拍用户关注时候的接口", "weipaiSubscribe", "奥尔图微拍接口调用成功了", 1); } else { WXLogs.AddLog(wid, "微拍用户关注时候的接口", "weipaiSubscribe", "奥尔图微拍接口调用失败:" + dict["returnmessage"].ToString(), 0); } return(returnCode); } catch (Exception ex) { WXLogs.AddLog(wid, "微拍用户关注时候的接口", "weipaiSubscribe", "报错:" + ex.Message, 0); return(ex.Message); } }
/// <summary> /// 是否为微拍的关键词 /// </summary> /// <param name="keywordsStr">关键词字符串,类似 abc,cda,dds,</param> /// <param name="wid">微帐号id</param> /// <returns></returns> public bool isWeipaiKeyWord(string keywordsStr, int wid) { WeiXinPF.BLL.wx_paizhao_setting setBll = new WeiXinPF.BLL.wx_paizhao_setting(); WeiXinPF.Model.wx_paizhao_setting setting = setBll.GetModelByWid(wid); if (setting == null || setting.isOpen == false || keywordsStr.IndexOf(setting.enterKeyWords + ",") < 0) { return(false); } else { return(true); } }
/// <summary> /// 处理微拍的程序 /// </summary> /// <param name="keywords"></param> /// <returns></returns> public string weipai_promptStr(string keywords, int wid) { string ret = ""; WeiXinPF.BLL.wx_paizhao_setting setBll = new WeiXinPF.BLL.wx_paizhao_setting(); WeiXinPF.Model.wx_paizhao_setting setting = setBll.GetModelByWid(wid); if (setting == null || setting.isOpen == false || setting.enterKeyWords != keywords) { return(""); } else { ret = setting.prompt.ToString(); } return(ret); }
/// <summary> /// 得到一个对象实体 /// </summary> public WeiXinPF.Model.wx_paizhao_setting DataRowToModel(DataRow row) { WeiXinPF.Model.wx_paizhao_setting model = new WeiXinPF.Model.wx_paizhao_setting(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["wid"] != null && row["wid"].ToString() != "") { model.wid = int.Parse(row["wid"].ToString()); } if (row["isOpen"] != null && row["isOpen"].ToString() != "") { if ((row["isOpen"].ToString() == "1") || (row["isOpen"].ToString().ToLower() == "true")) { model.isOpen = true; } else { model.isOpen = false; } } if (row["enterKeyWords"] != null) { model.enterKeyWords = row["enterKeyWords"].ToString(); } if (row["prompt"] != null) { model.prompt = row["prompt"].ToString(); } if (row["outKeyWords"] != null) { model.outKeyWords = row["outKeyWords"].ToString(); } if (row["initApiUrl"] != null) { model.initApiUrl = row["initApiUrl"].ToString(); } if (row["picApiUrl"] != null) { model.picApiUrl = row["picApiUrl"].ToString(); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WeiXinPF.Model.wx_paizhao_setting model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update wx_paizhao_setting set "); strSql.Append("wid=@wid,"); strSql.Append("isOpen=@isOpen,"); strSql.Append("enterKeyWords=@enterKeyWords,"); strSql.Append("prompt=@prompt,"); strSql.Append("outKeyWords=@outKeyWords,"); strSql.Append("initApiUrl=@initApiUrl,"); strSql.Append("picApiUrl=@picApiUrl"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@wid", SqlDbType.Int, 4), new SqlParameter("@isOpen", SqlDbType.Bit, 1), new SqlParameter("@enterKeyWords", SqlDbType.VarChar, 100), new SqlParameter("@prompt", SqlDbType.VarChar, 500), new SqlParameter("@outKeyWords", SqlDbType.VarChar, 100), new SqlParameter("@initApiUrl", SqlDbType.VarChar, 500), new SqlParameter("@picApiUrl", SqlDbType.VarChar, 500), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.wid; parameters[1].Value = model.isOpen; parameters[2].Value = model.enterKeyWords; parameters[3].Value = model.prompt; parameters[4].Value = model.outKeyWords; parameters[5].Value = model.initApiUrl; parameters[6].Value = model.picApiUrl; parameters[7].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(WeiXinPF.Model.wx_paizhao_setting model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into wx_paizhao_setting("); strSql.Append("wid,isOpen,enterKeyWords,prompt,outKeyWords,initApiUrl,picApiUrl)"); strSql.Append(" values ("); strSql.Append("@wid,@isOpen,@enterKeyWords,@prompt,@outKeyWords,@initApiUrl,@picApiUrl)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@wid", SqlDbType.Int, 4), new SqlParameter("@isOpen", SqlDbType.Bit, 1), new SqlParameter("@enterKeyWords", SqlDbType.VarChar, 100), new SqlParameter("@prompt", SqlDbType.VarChar, 500), new SqlParameter("@outKeyWords", SqlDbType.VarChar, 100), new SqlParameter("@initApiUrl", SqlDbType.VarChar, 500), new SqlParameter("@picApiUrl", SqlDbType.VarChar, 500) }; parameters[0].Value = model.wid; parameters[1].Value = model.isOpen; parameters[2].Value = model.enterKeyWords; parameters[3].Value = model.prompt; parameters[4].Value = model.outKeyWords; parameters[5].Value = model.initApiUrl; parameters[6].Value = model.picApiUrl; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WeiXinPF.Model.wx_paizhao_setting GetModelByWid(int wid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,wid,isOpen,enterKeyWords,prompt,outKeyWords,initApiUrl,picApiUrl from wx_paizhao_setting "); strSql.Append(" where wid=@wid"); SqlParameter[] parameters = { new SqlParameter("@wid", SqlDbType.Int, 4) }; parameters[0].Value = wid; WeiXinPF.Model.wx_paizhao_setting model = new WeiXinPF.Model.wx_paizhao_setting(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 传图片 /// </summary> /// <param name="openid"></param> /// <param name="PicUrl"></param> /// <returns></returns> public string weipaiChuanTuPian(string openid, string PicUrl, int wid) { BLL.wx_userweixin uwbll = new BLL.wx_userweixin(); string wxId = uwbll.GetwxId(wid);//原始Id string returnCode = ""; WeiXinPF.BLL.wx_logs logBll = new WeiXinPF.BLL.wx_logs(); try { WeiXinPF.BLL.wx_paizhao_setting setBll = new WeiXinPF.BLL.wx_paizhao_setting(); WeiXinPF.Model.wx_paizhao_setting model = setBll.GetModelByWid(wid); if (model == null || model.isOpen == false) { return(""); } Dictionary <string, string> parameters = new Dictionary <string, string>(); string url = model.picApiUrl; // string userid = openid; string sourceid = wxId; // "gh_e2d7eb82cb50"; //该用户的来源,即关注的哪一个微信公众账号)、(微信号)原始ID string timestamp = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString(); string v = "2000"; string downurl = PicUrl; string signature = ""; parameters.Add("userid", openid); parameters.Add("sourceid", sourceid); parameters.Add("downurl", downurl); parameters.Add("timestamp", timestamp); parameters.Add("v", "2000"); signature = GetBizSign(parameters); string postParam = "userid=" + userid + "&downurl=" + downurl + "&sourceid=" + sourceid + "×tamp=" + timestamp + "&v=" + v + "&signature=" + signature; string ret = Utils.HttpPost(url, postParam); Dictionary <string, object> dict = MyCommFun.JsonToDictionary(ret); returnCode = dict["returncode"].ToString(); if (returnCode == "200") { //成功 WXLogs.AddLog(wid, "微拍传图的接口", "weipaiChuanTuPian", "奥尔图微拍接口调用成功了", 1); WeiXinPF.BLL.wx_paizhao_picinfo pBll = new WeiXinPF.BLL.wx_paizhao_picinfo(); WeiXinPF.Model.wx_paizhao_picinfo pic = new WeiXinPF.Model.wx_paizhao_picinfo(); pic.openid = openid; pic.picUrl = PicUrl; pic.createDate = DateTime.Now; pBll.Add(pic); return(dict["mentioninfo"].ToString()); } else { WXLogs.AddLog(wid, "微拍传图的接口", "weipaiChuanTuPian", "奥尔图微拍接口调用失败:" + dict["returnmessage"].ToString(), 0); return(dict["returnmessage"].ToString()); } } catch (Exception ex) { WXLogs.AddLog(wid, "微拍传图的接口", "weipaiChuanTuPian", "报错:" + ex.Message, 0); return("打印接口报错:" + ex.Message); } }