//根据客户id来获取使用哪个公众号的key,错误返回clsNetExecute.Error +错误信息;正确返回key值 private string GetTokenKey(string khid) { string errInfo, rt; string mysql = "select ccid+'-' from yx_t_khb where khid=@khid"; List <SqlParameter> para = new List <SqlParameter>(); para.Add(new SqlParameter("@khid", khid)); DataTable dt; using (LiLanzDALForXLM dal = new LiLanzDALForXLM("server='192.168.35.10';uid=ABEASD14AD;pwd=+AuDkDew;database=tlsoft")) { errInfo = dal.ExecuteQuerySecurity(mysql, para, out dt); } if (errInfo != "") { rt = clsNetExecute.Error + errInfo; } else if (dt.Rows.Count > 0) { if (Convert.ToString(dt.Rows[0][0]).IndexOf("-17832-") > 0) { rt = "7"; } else { rt = "5"; } } else { rt = clsNetExecute.Error + "系统未找到该客户信息"; } return(rt); }
//微信卡券 //查询CODE接口--卡卷查询 public string CheckCode(string code, string configkey) { string rtJson = @"{{""can_consume"":{0},""card_status"":""{1}"",""card_description"":""{3}"",""card_discount"":""{4}"",""errmsg"":""{2}"",""localtype"":""{5}"",""leastcost"":""{6}"",""reducecost"":""{7}""}}"; using (LiLanzDALForXLM dal62 = new LiLanzDALForXLM(WXDBConstr)) { string url = string.Format("https://api.weixin.qq.com/card/code/get?access_token={0}", GetToken(configkey)); List <SqlParameter> paras = new List <SqlParameter>(); string str_sql = "", errinfo = ""; string datas = @"{{ ""code"" : ""{0}"", ""check_consume"" : false }}"; datas = string.Format(datas, code); string content = PostDataToWX(url, datas); JObject jo = JObject.Parse(content); if (Convert.ToString(jo["errcode"]) == "0") { string can_consume = Convert.ToString(jo["can_consume"]).ToLower(); string openid = Convert.ToString(jo["openid"]); string status = Convert.ToString(jo["user_card_status"]); string cardid = Convert.ToString(jo["card"]["card_id"]); str_sql = @" if exists (select top 1 1 from wx_t_cardinfos where cardid=@cardid and configkey=@configkey and isdel=0) begin if exists (select top 1 1 from wx_t_cardcodes where cardid=@cardid and cardcode=@cardcode) update wx_t_CardCodes set getuser=@openid,usercardstatus=@status,canconsume=@canconsume where cardid=@cardid and cardcode=@cardcode; else insert into wx_t_CardCodes(cardid,cardcode,isget,getuser,gettime,isconsume,usercardstatus,canconsume) values(@cardid,@cardcode,1,@openid,getdate(),0,'NORMAL',@canconsume); select top 1 '11',description,localdiscount,localcardtype,LeastCost,ReduceCost from wx_t_cardinfos where cardid=@cardid and configkey=@configkey and isdel=0; end else select '00';"; paras.Clear(); paras.Add(new SqlParameter("@cardid", cardid)); paras.Add(new SqlParameter("@configkey", configkey)); paras.Add(new SqlParameter("@openid", openid)); paras.Add(new SqlParameter("@status", status)); paras.Add(new SqlParameter("@canconsume", can_consume)); paras.Add(new SqlParameter("@cardcode", code)); DataTable dt = null; errinfo = dal62.ExecuteQuerySecurity(str_sql, paras, out dt); if (errinfo != "") { //WriteLog("CheckCode WriteDB Is ERROR!" + errinfo); rtJson = string.Format(rtJson, can_consume, status, errinfo, "", "", "", "", ""); } else { if (Convert.ToString(dt.Rows[0][0]) == "00") { rtJson = string.Format(rtJson, can_consume, status, "该卡券已停用!", "", "", "", "", ""); } else { rtJson = string.Format(rtJson, can_consume, status, "", Convert.ToString(dt.Rows[0][1]), Convert.ToString(dt.Rows[0][2]), Convert.ToString(dt.Rows[0][3]), Convert.ToString(dt.Rows[0][4]), Convert.ToString(dt.Rows[0][5])); } } } else { rtJson = string.Format(rtJson, "false", "", jo["errmsg"], "", "", "", "", ""); } } return(rtJson); }