コード例 #1
0
        private void MainToMessage(HttpContext context)
        {
            string ls_GoodsImg_Code = "", ls_Code = "";

            try
            {
                ls_GoodsImg_Code = context.Request["id"];
                ls_Code          = context.Request["code"];
            }
            catch { context.Response.Write(""); return; }
            if (string.IsNullOrEmpty(ls_Code) && string.IsNullOrEmpty(ls_GoodsImg_Code))
            {
                context.Response.Write(""); return;
            }
            else
            {
                GyShop_Page.SetSession();
                if (ls_GoodsImg_Code == "0")//获取缩略图
                {
                    context.Response.Write(Of_ThumbnaiIimg(ls_Code));
                    return;
                }
                if (ls_GoodsImg_Code == "1")//获取图文详情
                {
                    context.Response.Write(Of_GoodsImg(ls_Code));
                    return;
                }
                else
                {
                    context.Response.Write(""); return;
                }
            }
        }
コード例 #2
0
        private void SendMessage(HttpContext context)
        {
            string Express_type = context.Request.Form["Express_type"].ToString();
            string Express_code = context.Request.Form["Express_code"].ToString();
            string goo_str      = context.Request.Form["goo_str"].ToString();
            string ls_num       = context.Request.Form["num"].ToString();
            string out_no       = context.Request.Form["out_no"].ToString();

            if (string.IsNullOrEmpty(Express_type) || string.IsNullOrEmpty(Express_code) || string.IsNullOrEmpty(goo_str) || string.IsNullOrEmpty(ls_num))
            {
                HttpContext.Current.Response.Write("参数不完整");
                return;
            }
            GyShop_Page.SetSession();
            string AppID       = "";
            string AppSecret   = "";
            string template_id = "";
            string Mobile      = "";
            string WeixinID    = "";

            AppID       = publicfuns.of_GetMySysSet("weixin", "appid").Replace(" ", "");
            AppSecret   = publicfuns.of_GetMySysSet("weixin", "appsecret").Replace(" ", "");
            template_id = publicfuns.of_GetMySysSet("weixin", "templateid").Replace(" ", "");
            if (AppID == "" || AppSecret == "" || template_id == "")
            {
                HttpContext.Current.Response.Write("公众号信息不完整!");
                return;
            }
            string ls_Sql = "SELECT weixinid FROM customer where mobile=@mobile";

            GysoftParameter[] Pa = { new GysoftParameter("@mobile", Mobile) };
            WeixinID = SqlHelper.ExecuteScalar(ls_Sql, Pa);
            if (WeixinID == "" || WeixinID == null)
            {
                HttpContext.Current.Response.Write("该手机号未绑定微信!"); return;
            }
            string access_token = "";

            SysVisitor.Current.UserWeixinID = WeixinID;
            string touser = WeixinID;
            string url    = "";
            string menu   = "{";

            menu += "\"touser\":\"" + touser + "\",";
            menu += "\"template_id\":\"" + template_id + "\",";
            menu += "\"url\":\"" + url + "\",";
            menu += "\"topcolor\":\"#FF0000\",";
            menu += "\"data\":{";
            menu += "\"keyword1\": {";
            menu += "\"value\":\"" + Express_type + "\",";
            menu += "\"color\":\"#173177\"";
            menu += "},";
            menu += "\"keyword2\":{";
            menu += "\"value\":\"" + Express_code + "\",";
            menu += "\"color\":\"#173177\"";
            menu += "},";
            menu += "\"keyword3\":{";
            menu += "\"value\":\"" + goo_str + "\r\n 出货单号为:" + out_no + "\",";
            menu += "\"color\":\"#173177\"";
            menu += "},";
            menu += "\"keyword4\":{";
            menu += "\"value\":\"" + ls_num + "\",";
            menu += "\"color\":\"#173177\"";
            menu += "}";
            menu += "}";
            menu += "}";
            JObject json = JObject.Parse(menu);

            menu = json.ToString();

            string    json_access_token = getPageInfo(string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", AppID, AppSecret));
            DataTable dt = Json.JsonToDataTable(json_access_token);

            try
            {
                access_token = dt.Rows[0]["access_token"].ToString();
            }
            catch (Exception ex) { HttpContext.Current.Response.Write(json_access_token + ex.Message + AppID + "|" + AppSecret + "|" + dt.Rows[0][0].ToString()); return; }
            string content = Of_PostStr(string.Format("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}", access_token), menu);

            HttpContext.Current.Response.Write(content);
        }
コード例 #3
0
        /// <summary>
        /// 模板消息,客服消息接口
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            Encoding UTF8 = Encoding.GetEncoding("UTF-8");

            Response.ContentEncoding = UTF8;
            string AppID       = "";
            string AppSecret   = "";
            string template_id = "";
            string Mobile      = "";
            string WeixinID    = "";
            string Content     = "";

            Response.ContentType = "text/plain";

            if (Request.HttpMethod.ToLower() == "get")      //接口认证,用get访问
            {
                #region 模板消息
                if (!string.IsNullOrEmpty(Request.QueryString["mobile"]) && !string.IsNullOrEmpty(Request.QueryString["content"]))
                {
                    Mobile  = Request.QueryString["mobile"];
                    Content = Server.UrlDecode(Request.QueryString["content"]);

                    if (Mobile == null || Content == null)
                    {
                        Response.Write("Error");
                        return;
                    }
                    string[] str = Content.Split('|');
                    if (str.Length < 4)
                    {
                        Response.Write("消息参数不足,参数按顺序为快递类型、快递单号、商品信息、商品数量、出货单号(可不加) 并用|隔开");
                        return;
                    }
                    GyShop_Page.SetSession();


                    // txt_Code.Text = publicfuns.of_GetMySysSet("weixin", "code");
                    AppID       = publicfuns.of_GetMySysSet("weixin", "appid").Replace(" ", "");
                    AppSecret   = publicfuns.of_GetMySysSet("weixin", "appsecret").Replace(" ", "");
                    template_id = publicfuns.of_GetMySysSet("weixin", "templateid").Replace(" ", "");

                    if (AppID == "" || AppSecret == "" || template_id == "")
                    {
                        Response.Write("公众号信息不完整!"); return;
                    }

                    string            ls_Sql = "SELECT weixinid FROM customer where mobile=@mobile";
                    GysoftParameter[] Pa     = { new GysoftParameter("@mobile", Mobile) };
                    WeixinID = SqlHelper.ExecuteScalar(ls_Sql, Pa);

                    if (WeixinID == "" || WeixinID == null)
                    {
                        Response.Write("该手机号未绑定微信!"); return;
                    }
                    //接受信息    快递公司  运单号  商品信息  发货数量
                    string access_token = "";
                    SysVisitor.Current.UserWeixinID = WeixinID;
                    string touser = WeixinID; // "owF65jrL27XSMidPDSnsrcFAhOK8";//用户微信ID
                    //string template_id = "ZkjAZNDSU9RRQYQLwo-51oMc4FDVF1yp3oeh8fGTdKA";//模板ID
                    string keyword1 = str[0]; //快递类型
                    string keyword2 = str[1]; //快递单号
                    string keyword3 = str[2]; //商品信息
                    string keyword4 = str[3]; //商品数量
                    string outone   = "";
                    try
                    {
                        outone = str[4];//出货单号
                    }
                    catch { }
                    string url = "";// SysVisitor.Current.WebUrl + "/Dw_OutMany.aspx?UserKey = " + UserInfo.GetUserKey() + "&OutNo=" + str[4];//跳转URL 为空时Android端不可点击,IOS端点击进去为空页面

                    string menu = "{";
                    menu += "\"touser\":\"" + touser + "\",";
                    menu += "\"template_id\":\"" + template_id + "\",";
                    menu += "\"url\":\"" + url + "\",";
                    menu += "\"topcolor\":\"#FF0000\",";
                    menu += "\"data\":{";
                    menu += "\"first\":{";
                    menu += "\"value\":\"" + "你订购的XXX已发货" + "\",";
                    menu += "\"color\":\"#173177\"";
                    menu += "},";
                    menu += "\"keyword1\": {";
                    menu += "\"value\":\"" + keyword1 + "\",";
                    menu += "\"color\":\"#173177\"";
                    menu += "},";
                    menu += "\"keyword2\":{";
                    menu += "\"value\":\"" + keyword2 + "\",";
                    menu += "\"color\":\"#173177\"";
                    menu += "},";
                    menu += "\"keyword3\":{";
                    menu += "\"value\":\"" + keyword3 + "\r\n 出货单号为:" + outone + "\",";
                    menu += "\"color\":\"#173177\"";
                    menu += "},";
                    menu += "\"keyword4\":{";
                    menu += "\"value\":\"" + keyword4 + "\",";
                    menu += "\"color\":\"#173177\"";
                    menu += "},";
                    menu += "\"remark\":{";
                    menu += "\"value\":\"" + "详情请咨询XXX" + "\",";
                    menu += "\"color\":\"#173177\"";
                    menu += "}";
                    menu += "}";
                    menu += "}";

                    JObject json = JObject.Parse(menu);
                    //json["data"]["keyword1"]["value"] = "天天快递";
                    //json.Add("data",(new JProperty("keyword5",

                    //    new JObject(new JProperty("value", "1234"), new JProperty("color", "#131313")))));


                    menu = json.ToString();

                    string    json_access_token = getPageInfo(string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", AppID, AppSecret));
                    DataTable dt = Json.JsonToDataTable(json_access_token);
                    try
                    {
                        access_token = dt.Rows[0]["access_token"].ToString();
                    }
                    catch (Exception ex) { Response.Write(json_access_token + ex.Message + AppID + "|" + AppSecret + "|" + dt.Rows[0][0].ToString()); return; }
                    string content = Of_PostStr(string.Format("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}", access_token), menu);


                    Response.Write(content);
                }
                else
                {
                    Response.Write("error");
                    Response.End();
                }
                #endregion

                if (!string.IsNullOrEmpty(Request.QueryString["message"]))
                {
                }
            }
        }
コード例 #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Encoding gb2312 = Encoding.GetEncoding("gb2312");

            Response.ContentEncoding = gb2312;

            #region 处理Post请求
            if (Request.RequestType == "POST")
            {
                GyShop_Page.SetSession();
                string Edit     = Request.Form["Edit"].ToString();
                string scr      = Request.Form["imgscr"].ToString();//缩略图路径
                string user     = Request.Form["username"].ToString();
                string passwd   = Request.Form["password"].ToString();
                string goods_no = Request.Form["goods_no"].ToString();
                string text     = Server.UrlDecode(Request.Form["text"].ToString());
                text = HttpUtility.UrlDecode(text, Encoding.GetEncoding("UTF-8"));

                string str = SureSaleInfo(user, passwd, as_Code);//SaleInfo.SureSaleInfo(user, passwd);

                #region 保存产品图文详情
                if (str == "OK" && Edit == "false" || Edit == "true")
                {
                    int count = 0;
                    count = SqlHelper.ExecuteScalarNum("select count(*) from Goodsno_picture where Goo_code=@Goo_code", "@Goo_code=" + goods_no);
                    n_create_sql lnv_sql = new n_create_sql();
                    lnv_sql.of_SetTable("Goodsno_picture");
                    if (count <= 0)
                    {
                        lnv_sql.of_AddCol("Goo_code", goods_no);
                    }
                    lnv_sql.of_AddCol("Memo", text);
                    lnv_sql.of_AddCol("Human", user);
                    lnv_sql.of_AddCol("Insdate", DateTime.Now.ToString());
                    lnv_sql.of_AddCol("Same_code", "");
                    if (scr != "")
                    {
                        lnv_sql.of_AddCol("ThumbnaiIimg", scr);
                    }
                    int li_count = 0;
                    if (count <= 0)
                    {
                        li_count = lnv_sql.of_execute();//insert
                    }
                    else
                    {
                        li_count = lnv_sql.of_execute("Goo_code=@Goo_code", "@Goo_code=" + goods_no);//update
                    }
                    if (li_count > 0)
                    {
                        Response.Write("OK");
                    }
                    else
                    {
                        Response.Write("Error");
                    }
                    return;
                }
                #endregion

                if (str == "OK" && Edit == "DefaulePictrueAdd")//增加首页轮播图
                {
                    string            strSql = "insert into mysysset(itemType,itemName,itemvalue,memo) values('微信商城焦点图',@itemName,@itemvalue,@memo)";
                    GysoftParameter[] Pa     = { new GysoftParameter("@itemName", goods_no), //title
                                                 new GysoftParameter("@itemvalue", scr),     //Pictrue
                                                 new GysoftParameter("@memo", text) };       //href
                    int li_Rel = 0;
                    li_Rel = SqlHelper.ExecuteNonQuery(strSql, Pa);
                    if (li_Rel > 0)
                    {
                        Response.Write("OK");
                    }
                    else
                    {
                        Response.Write("Error;可能标题重复");
                    }
                    return;
                }
                if (str == "OK" && Edit == "DefaulePictrueDel")//删除首页轮播图
                {
                    string            StrSql = "DELETE from mysysset WHERE itemType='微信商城焦点图' AND itemvalue=@itemvalue";
                    GysoftParameter[] Pa     = { new GysoftParameter("@itemvalue", scr) };
                    int li_Rel = SqlHelper.ExecuteNonQuery(StrSql, Pa);
                    if (li_Rel > 0)
                    {
                        Response.Write("OK");
                    }
                    else
                    {
                        Response.Write("Error");
                    }

                    return;
                }
                else
                {
                    str = HttpUtility.UrlDecode(str, Encoding.GetEncoding("UTF-8"));
                    Response.Write(str);
                    return;
                }
            }
            #endregion

            #region 处理Get请求
            GyShop_Page.SetSession();
            url = HttpContext.Current.Request.Url.Query;
            string username = Request["username"];
            string password = Request["password"];
            string code1    = Request["code"];
            string askey    = Request["askey"];
            string ls_Rel   = "Error";
            if (Request["askey"] == null)
            {
                if (url == "" || Request["username"] == null || Request["password"] == null)
                {
                    Response.Write("Error");
                    return;
                }
                ls_Rel = SureSaleInfo(username, password, code1);//SaleInfo.SureSaleInfo(username, password);
                if (ls_Rel == "OK" && askey == null)
                {
                    string ls_isdebug = ConfigurationManager.AppSettings["debug"].ToString();
                    if (ls_isdebug == "Y")
                    {
                        Response.Write("软件正在维护中,请稍后再试");
                        return;
                    }
                    Response.Write("OK");
                    return;
                }
                else
                {
                    Response.Write(ls_Rel);
                }
            }
            else if (askey != null)
            {
                try
                {
                    askey = baseclass.DES.of_DecryStrVc(askey, Key);
                }
                catch
                {
                    Response.Write("参数不能被识别");
                    return;
                }
                askey = HttpUtility.UrlDecode(askey, Encoding.GetEncoding("UTF-8"));
                if (askey == "menu")//拉取商品种类列表
                {
                    string    sql = "Select typeNo,typeName From goodtype Where isWeb='Y' And isnull(visible,'Y')='Y' order by seq";
                    DataTable dt  = SqlHelper.ExecuteDataTable(sql);
                    string    str = Json.DataTableToJson(dt);
                    Response.Write(str);
                    return;
                }
                if (askey == "DefaultPicture")//拉取首页图片
                {
                    string    strSql     = "select itemName,itemvalue,memo from mysysset where itemType='微信商城焦点图' order by itemName desc";
                    DataTable ldt_PPTBox = SqlHelper.ExecuteDataTable(strSql);
                    string    str        = Json.DataTableToJson(ldt_PPTBox);
                    Response.Write(str);
                    return;
                }
                else
                {
                    string[] str = askey.Split('|');
                    #region 拉取产品信息列表
                    if (str.Length == 3)
                    {
                        string row          = str[0].Trim();
                        string menu         = str[1].Trim();
                        string name         = str[2].Trim();
                        int    li_PageIndex = 1;

                        string      ls_sql  = @"select goodsno.goo_name,goodsno.goo_code,goodsno.goo_no 
                                        from goodsno,goodmate,goodtype 
                                        where 1=1 
                                        and goo_type=typeno and goo_mate*=matecode and goodsno.Goodfunc in ('C','X') 
                                        and goodtype.isweb='Y' and goodmate.isweb='Y' and goodsno.isweb='Y'";
                        n_findby_dw lnv_sql = new n_findby_dw();
                        lnv_sql.of_setSQL(ls_sql);
                        lnv_sql.of_SetOr("goo_no", "goodsno.goo_no", "like", name);
                        lnv_sql.of_SetOr("goo_no", "goodsno.goo_name", "like", name);
                        lnv_sql.of_SetCol("goo_type", "goodsno.goo_type", "=", menu);

                        int       count     = 0;
                        DataTable ldt_Goods = new DataTable();
                        ldt_Goods = lnv_sql.Of_GetPageDataTable("goodsno.goo_code", Convert.ToInt32(row), li_PageIndex, ref count);
                        string str_dt = Json.DataTableToJson(ldt_Goods);
                        Response.Write(str_dt);
                        return;
                    }
                    #endregion

                    #region 为经销商微信生成初始密码,获取初始密码
                    if (str.Length == 4)
                    {
                        string generate = str[0].Trim();
                        string value    = str[1].Trim();
                        string user     = str[2].Trim();
                        string passwd   = str[3].Trim();
                        string code     = as_Code;

                        ls_Rel = SureSaleInfo(user, passwd, code);
                        if (ls_Rel == "OK")
                        {
                            return;                                       //此接口不再使用

                            if (generate == "generate" && value == "set") //校验值set为生成密码操作 get为获取密码操作
                            {
                                string ls_sql   = "select count(*) WeixinPwd from customer where WeixinPwd is null";
                                string ls_Temp  = SqlHelper.ExecuteScalar(ls_sql);
                                int    ls_count = 0;
                                try
                                { ls_count = Convert.ToInt32(ls_Temp); }
                                catch { ls_count = 0; }
                                if (ls_count == 0)//不存在值为空的密码列
                                {
                                    Response.Write("1"); return;
                                }
                                try
                                {
                                    int    RandKey = 0;
                                    Random ran     = new Random();//Random对象放在循环外面,否则大概率重复
                                    for (int i = 0; i < ls_count; i++)
                                    {
                                        RandKey = ran.Next(1000, 9999);
                                        string            WeixinPwd = baseclass.DES.of_EncryStrVc(RandKey.ToString(), ls_DESKey);
                                        string            ls_Sql    = "set rowcount 1 update customer set WeixinPwd=@WeixinPwd where WeixinPwd is null";
                                        GysoftParameter[] Pa        = { new GysoftParameter("@WeixinPwd", WeixinPwd) };
                                        SqlHelper.ExecuteNonQuery(ls_Sql, Pa);
                                    }
                                    Response.Write("0");
                                    return;
                                }
                                catch (Exception ex)
                                { Response.Write(ex.Message); return; }
                            }
                            if (generate == "generate" && value == "get")//获取经销商初始密码
                            {
                                string    ls_Sql  = "select mobile,WeixinPwd from customer";
                                DataTable ldt_pwd = SqlHelper.ExecuteDataTable(ls_Sql);
                                string    ls_pwd  = Json.DataTableToJson(ldt_pwd);
                                Response.Write(ls_pwd);
                                return;
                            }
                        }
                    }
                    #endregion

                    #region 获取产品图文详情

                    string[] str1 = askey.Split('!');
                    if (str1.Length == 3)
                    {
                        string goocode = str1[0].Trim();
                        string user    = str1[1].Trim();
                        string passwd  = str1[2].Trim();
                        string code    = as_Code;
                        ls_Rel = SureSaleInfo(user, passwd, code);
                        if (ls_Rel == "OK")
                        {
                            string            ls_Sql = "select Memo from Goodsno_picture where Goo_code=@Goo_code";
                            GysoftParameter[] Pa     =
                            {
                                new GysoftParameter("@Goo_code", goocode)
                            };
                            //DataTable ldt_user = SqlHelper.ExecuteDataTable(CommandType.Text, ls_Sql, Pa);
                            //string ls_json = Json.DataTableToJson(ldt_user);
                            //if (ls_json == "[]")
                            //{ Response.Write(""); }
                            //else
                            //Response.Write(ls_json);
                            string ldt_user = SqlHelper.ExecuteScalar(ls_Sql, Pa);
                            Response.Write(ldt_user);
                            return;
                        }
                    }

                    #endregion
                    else
                    {
                        Response.Write("error" + "key:" + Key + "  askey:" + askey); return;
                    }
                }
            }
            #endregion
        }