Esempio n. 1
0
    //支付成功时执行的操作
    private void PayOrder_Success(WxPayData result)
    {
        ZLLog.L(ZLEnum.Log.pay, PayPlat + " 支付单:" + result.GetValue("out_trade_no") + " 金额:" + result.GetValue("total_fee"));
        try
        {
            M_Order_PayLog paylogMod = new M_Order_PayLog();
            M_Payment      pinfo     = payBll.SelModelByPayNo(result.GetValue("out_trade_no").ToString());
            if (pinfo == null)
            {
                throw new Exception("支付单不存在");
            }                                                    //支付单检测合为一个方法
            if (pinfo.Status != (int)M_Payment.PayStatus.NoPay)
            {
                throw new Exception("支付单状态不为未支付");
            }
            pinfo.Status       = (int)M_Payment.PayStatus.HasPayed;
            pinfo.PlatformInfo = PayPlat;
            pinfo.SuccessTime  = DateTime.Now;
            pinfo.PayTime      = DateTime.Now;
            pinfo.CStatus      = true;
            //1=100,
            double tradeAmt = Convert.ToDouble(result.GetValue("total_fee")) / 100;
            pinfo.MoneyTrue = tradeAmt;
            payBll.Update(pinfo);
            DataTable orderDT = orderBll.GetOrderbyOrderNo(pinfo.PaymentNum);
            foreach (DataRow dr in orderDT.Rows)
            {
                M_OrderList orderMod = orderBll.SelModelByOrderNo(dr["OrderNo"].ToString());
                OrderHelper.FinalStep(pinfo, orderMod, paylogMod);
                //if (orderMod.Ordertype == (int)M_OrderList.OrderEnum.Purse)
                //{

                //    M_UserInfo mu = buser.SelReturnModel(orderMod.Userid);
                //    new B_Shop_MoneyRegular().AddMoneyByMin(mu, orderMod.Ordersamount, ",订单号[" + orderMod.OrderNo + "]");
                //}
                orderCom.SendMessage(orderMod, paylogMod, "payed");
                //orderCom.SaveSnapShot(orderMod);
                //发送微信消息
                B_UserAPP  userappBll = new B_UserAPP();
                M_UserAPP  userappMod = new M_UserAPP();
                M_UserInfo mu         = buser.GetUserByUserID(orderMod.Userid);
                userappMod = userappBll.SelModelByUid(mu.UserID, "wechat");
                if (userappMod != null)
                {
                    WxAPI  wxapi = WxAPI.Code_Get(1);
                    string json  = "{\"first\":{\"value\":\"您已成功支付" + orderMod.Ordersamount.ToString("0.00") + "元\",\"color\":\"#000\"},\"DateTime\":{\"value\":\"" + DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss") + "\",\"color\":\"#173177\"},\"PayAmount\":{\"value\":\"" + orderMod.Ordersamount.ToString("0.00") + "元\",\"color\":\"#173177\"},\"remark\":{\"value\":\"您的订单已成功付款!订单号:" + orderMod.OrderNo + "\",\"color\":\"#173177\"}}";
                    wxapi.Tlp_SendTlpMsg(userappMod.OpenID, "jAP4eGIOPvCdg33KBVDcClxRGYNNgcUpmHlVdO_FRV0", SiteConfig.SiteInfo.SiteUrl + "/User/Order/OrderProList?OrderNo=" + orderMod.OrderNo, json);
                }
            }
            ZLLog.L(ZLEnum.Log.pay, PayPlat + "成功!支付单:" + result.GetValue("out_trade_no").ToString());
        }
        catch (Exception ex)
        {
            ZLLog.L(ZLEnum.Log.pay, new M_Log()
            {
                Action  = "支付回调报错",
                Message = PayPlat + ",支付单:" + result.GetValue("out_trade_no").ToString() + ",原因:" + ex.Message
            });
        }
    }
Esempio n. 2
0
        private DataTable SendImage(M_WX_MsgTlp tlpMod, string appids)
        {
            DataTable   dt      = GetResultStruct();
            M_WXImgItem itemMod = JsonConvert.DeserializeObject <M_WXImgItem>(tlpMod.MsgContent);

            foreach (string id in appids.Split(','))
            {
                if (DataConvert.CLng(id) < 1)
                {
                    continue;
                }
                api = WxAPI.Code_Get(Convert.ToInt32(id));
                DataRow dr = dt.NewRow();
                dr["isok"]  = true;
                dr["appid"] = api.AppId.APPID.ToString();
                dr["alias"] = api.AppId.Alias;
                switch (Request["mode_rad"])
                {
                case "loop":
                    M_WxImgMsg imgMod = new M_WxImgMsg();
                    imgMod.Articles.Add(itemMod);
                    api.SendAllBySingle(imgMod);
                    break;
                }
            }
            return(dt);
        }
Esempio n. 3
0
 public string shareLink = "";//sharelink
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         M_UserInfo mu = buser.GetLogin();
         pageMod = GetScenceMod();
         if (!B_Design_Helper.Se_CheckAccessPwd(pageMod, mu))
         {
             Server.Transfer("/design/h5/checkpwd.aspx?sid=" + Sid + "&ztype=ppt");
             return;
         }
         //shareLink = Request.Url.Host + "/h5/" + pageMod.ID;
         if (DeviceHelper.GetBrower() == DeviceHelper.Brower.Micro)
         {
             try
             {
                 //Avoid sometimes WeChat API parsing error
                 WX_Share.Visible = true;
                 //--WXAPI
                 WxAPI api = WxAPI.Code_Get();
                 appid     = api.AppId.APPID;
                 timeStamp = WxAPI.HP_GetTimeStamp();
                 sign      = api.JSAPI_GetSign(api.JSAPITicket, noncestr, timeStamp, Request.Url.AbsoluteUri);
             }
             catch (Exception ex) { ZLLog.L("wxerror:" + ex.Message); }
         }
         Title_L.Text = pageMod.Title;
         if (string.IsNullOrEmpty(pageMod.PreviewImg))
         {
             string[] defwx = "/UploadFiles/demo/h4.jpg|/UploadFiles/demo/h5.jpg".Split('|');
             pageMod.PreviewImg = defwx[new Random().Next(0, defwx.Length)];
         }
         Wx_Img.ImageUrl = pageMod.PreviewImg;
     }
 }
        protected void ReToken_Btn_Click(object sender, EventArgs e)
        {
            WxAPI api = WxAPI.Code_Get(Mid);

            api.GetToken();
            function.WriteSuccessMsg("已重新获取Token");
        }
Esempio n. 5
0
        protected void SaveNew_B_Click(object sender, EventArgs e)
        {
            List <M_WXImgItem> imgList = JsonConvert.DeserializeObject <List <M_WXImgItem> >(Article_Hid.Value);

            //替换img路径
            foreach (var item in imgList)
            {
                item.Description = htmlHelp.ConvertImgUrl(item.Description, "http://" + Request.Url.Authority);
                if (!string.IsNullOrEmpty(MediaID) && (item.PicUrl.Contains("https://") || item.PicUrl.Contains("http://")))//当为修改图文时判断路径是否为网络格式
                {
                    item.PicUrl = GetImgVpath(item.PicUrl);
                }
            }
            if (!string.IsNullOrEmpty(Request.Form["appids"]))
            {
                string[] appids = Request.Form["appids"].Split(',');
                foreach (var item in appids)
                {
                    WxAPI  m_api  = WxAPI.Code_Get(Convert.ToInt32(item));
                    string result = UpMpNews(imgList);
                    if (!result.Contains("errcode"))
                    {
                        function.WriteSuccessMsg("操作成功!", "WxMaterial.aspx?type=news&appid=" + AppID);
                    }
                    else
                    {
                        function.WriteSuccessMsg("操作失败!原因:" + result);
                    }
                }
            }
            else
            {
                function.WriteErrMsg("请选择微信公众号!");
            }
        }
Esempio n. 6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int appid = DataConverter.CLng(Request.QueryString["appid"]);

            try
            {
                TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
                timestr = Convert.ToInt64(ts.TotalSeconds).ToString();

                WxAPI wxapi = WxAPI.Code_Get(appid);
                appMod = appBll.SelReturnModel(appid);
                string result = APIHelper.GetWebResult("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appMod.APPID + "&secret=" + appMod.Secret);
                if (result.Contains("errcode"))
                {
                    wxapi.ErroMsg(result);
                }
                //{"access_token":"7EHneznPapbfKYIQISQGVw4comvbkxIWe5e7JmTkp2Y5P93aIO5FjjEeyvk65L4lcPeL6VuMOMZ7CKel95L_ljZnjZrdi-MGPK9mZZOuSN8","expires_in":7200}
                JObject obj = JsonConvert.DeserializeObject <JObject>(result);
                appMod.Token     = obj["access_token"].ToString();
                appMod.TokenDate = DateTime.Now;
                appBll.UpdateByID(appMod);

                string  jsapi_ticket = APIHelper.GetWebResult("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + appMod.Token + "&type=jsapi");
                JObject jsapi_obj    = (JObject)JsonConvert.DeserializeObject(jsapi_ticket);
                string  stringA      = "jsapi_ticket=" + jsapi_obj["ticket"].ToString() + "&noncestr=" + nonceStr + "&timestamp=" + timestr + "&url=" + Request.Url.AbsoluteUri;
                paySign = EncryptHelper.SHA1(stringA).ToLower();
            }
            catch (Exception ex) { }
        }
    }
Esempio n. 7
0
 public string wxpush(string openid, string content, string key)
 {
     try
     {
         if (!key.Equals(APIKey))
         {
             retMod.retmsg = "key不正确";
         }
         else if (string.IsNullOrEmpty(openid))
         {
             retMod.retmsg = "未指定openid";
         }
         else if (string.IsNullOrEmpty(content))
         {
             retMod.retmsg = "内容不能为空";
         }
         else
         {
             WxAPI api = WxAPI.Code_Get();
             retMod.result  = api.SendMsg(openid, HttpUtility.UrlDecode(content));
             retMod.retcode = M_APIResult.Success;
         }
     }
     catch (Exception ex) { ZLLog.L("wxpush failed:[" + openid + "][" + content + "]" + ex.Message); retMod.retmsg = ex.Message; }
     return(retMod.ToString());
 }
Esempio n. 8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.HttpMethod == "GET")
        {
            Auth(); return;
        }
        try
        {
            buser      = new B_User(HttpContext.Current);
            requesdata = GetXml();
            //requesdata = "<xml><ToUserName><![CDATA[gh_33273dafc0e4]]></ToUserName> <FromUserName><![CDATA[olwfpsvje_OHogJ8rOANahcqSijk]]></FromUserName> <CreateTime>1434081760</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[pic]]></Content> <MsgId>6159334259197323209</MsgId> </xml>";
            if (string.IsNullOrEmpty(requesdata))
            {
                return;
            }
            M_WxTextMsg reqMod = new M_WxTextMsg(requesdata);
            //获取需要返回的公众号
            M_WX_APPID appmod = appBll.GetAppByWxNo(reqMod.ToUserName);
            if (appmod == null)
            {
                throw new Exception("目标公众号[" + reqMod.ToUserName + "]不存在");
            }
            api     = WxAPI.Code_Get(appmod);
            errmsg += "动作:" + reqMod.MsgType;
            switch (reqMod.MsgType)
            {
            case "event":    //事件--关注处理,后期扩展单击等
            {
                //M_WxImgMsg msgMod = JsonConvert.DeserializeObject<M_WxImgMsg>(appmod.WelStr);
                M_WxImgMsg msgMod = new M_WxImgMsg();
                msgMod.ToUserName   = reqMod.FromUserName;
                msgMod.FromUserName = reqMod.ToUserName;
                WxEventHandler(reqMod);        //系统事件处理
                //登录检测,可按需取消或修改位置
                M_UserInfo mu = UserBindCheck(reqMod);
                //if (mu.IsNull)
                //{
                //    msgMod.Articles.Add(new M_WXImgItem()
                //    {
                //        Title = "请先关联用户",
                //        Description = "你尚未关联用户,点击登录关联用户",
                //        Url = baseUrl + "/User/Login.aspx?WXOpenID=" + reqMod.FromUserName
                //    });
                //    RepToClient(msgMod.ToXML());
                //}
                WxMenuBtnHandler(reqMod, msgMod, mu);
            }
            break;

            case "text":    //接收文本消息
            {
                string xml = UserTextDeal(reqMod);
                RepToClient(xml);
            }
            break;
            }
        }
        catch (Exception ex) { ZLLog.L("微信报错," + errmsg + ",数据:" + requesdata + ",原因:" + ex.Message); }
    }
        public void MyBind()
        {
            WxAPI  wxBll    = WxAPI.Code_Get(AppID);
            JArray newslist = JsonConvert.DeserializeObject <JArray>(wxBll.GetWxConfig("newsmaterial"));
            JToken news     = newslist.First(j => j["media_id"].ToString().Equals(MediaID));

            News_Hid.Value = JsonConvert.SerializeObject(news);
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     api = WxAPI.Code_Get(AppID);
     if (!IsPostBack)
     {
         MyBind();
         Call.SetBreadCrumb(Master, "<li><a href='" + CustomerPageAction.customPath2 + "Main.aspx'>工作台</a></li><li><a href='" + CustomerPageAction.customPath2 + "WeiXin/WxAppManage.aspx'>公众号管理</a></li><li class='active'>模板列表</li>");
     }
 }
 protected void SendAll_B_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(TxtContent.Text.Trim()))
     {
         function.WriteErrMsg("文本内容不能为空");
     }
     //往多个公众号下的用户发送信息
     if (!string.IsNullOrEmpty(Request.Form["appids"]))
     {
         string[] appids = Request.Form["appids"].Split(',');
         foreach (string id in appids)
         {
             WxAPI  itemApi = WxAPI.Code_Get(Convert.ToInt32(id));
             string result  = api.SendAllBySingle(TxtContent.Text);
         }
         function.WriteSuccessMsg("群体发送成功!");
     }
     else
     {
         function.WriteErrMsg("请选择公众号!");
     }
     #region 通过群发接口发送 disuse
     //switch (Request.Form["msgtype_rad"])
     //{
     //    case "image":
     //        if (!Path.GetExtension(image_up.FileName).ToLower().Equals(".jpg"))
     //        {
     //            function.WriteErrMsg("仅支持jpg图片");
     //        }
     //        else if (image_up.FileContent.Length < 100 || image_up.FileContent.Length > (1000 * 1024))
     //        {
     //            function.WriteErrMsg("文件的大小不符合规范");
     //        }
     //        string msg = wxBll.UploadImg(image_up.FileContent, Path.GetFileName(image_up.FileName));
     //        JObject jmsg = JsonConvert.DeserializeObject<JObject>(msg);
     //        if (jmsg["media_id"] != null)
     //        {
     //            string gid = "";
     //            M_WXAllMsg model = new M_WXAllMsg() { filter = new WXFiter() { group_id = gid, is_to_all = true }, msgtype = "image", image = new WXMsgMedia() { media_id = jmsg["media_id"].ToString() } };
     //            result = wxBll.SendAll(model);
     //        }
     //        break;
     //    default:
     //        if (string.IsNullOrEmpty(TxtContent.Text.Trim())) { function.WriteErrMsg("文本内容不能为空"); }
     //        result = wxBll.SendAll(TxtContent.Text, WxGroup_D.SelectedValue);
     //        break;
     //}
     //function.WriteErrMsg("发送结果:" + result);
     //JObject jobj = JsonConvert.DeserializeObject<JObject>(result);
     //if (Convert.ToInt32(jobj["errcode"]) == 0)
     //{
     //    function.WriteSuccessMsg("群发送成功!");
     //}
     //else { function.WriteErrMsg("发送失败,原因:" + result); }
     #endregion
 }
Esempio n. 12
0
        private DataTable SendMulti(M_WX_MsgTlp tlpMod, string appids)
        {
            DataTable          dt       = GetResultStruct();
            List <M_WXImgItem> itemList = JsonConvert.DeserializeObject <List <M_WXImgItem> >(tlpMod.MsgContent);

            foreach (string id in appids.Split(','))
            {
                if (DataConvert.CLng(id) < 1)
                {
                    continue;
                }
                api = WxAPI.Code_Get(Convert.ToInt32(id));
                DataRow dr = dt.NewRow();
                dr["isok"]  = true;
                dr["appid"] = api.AppId.APPID.ToString();
                dr["alias"] = api.AppId.Alias;
                //每个APPID都需要独立上传一次
                //----------------------------------------------
                try
                {
                    string media = "";
                    UploadMultiNews(itemList, ref media);
                    dr["media"] = media;
                    switch (Request["mode_rad"])
                    {
                    case "loop":
                    {
                        M_WxImgMsg msg = new M_WxImgMsg();
                        msg.Articles = itemList;
                        api.SendAllBySingle(msg);
                    }
                    break;

                    case "api":
                    default:
                    {
                        M_WXAllMsg model = new M_WXAllMsg()
                        {
                            filter = new M_WXFiter()
                            {
                                group_id = "", is_to_all = true
                            }, msgtype = "mpnews", mpnews = new M_WXMsgMedia()
                            {
                                media_id = media
                            }
                        };
                        api.SendAll(model);
                    }
                    break;
                    }
                }
                catch (Exception ex) { dr["result"] = ex.Message; dr["isok"] = false; }
                dt.Rows.Add(dr);
            }
            return(dt);
        }
Esempio n. 13
0
    protected void Page_Init(object sender, EventArgs e)
    {
        M_UserInfo mu1 = buser.GetLogin();

        if (mu1 == null || mu1.IsNull || mu1.UserID < 1)
        {
            Response.Redirect("/wxpromo.aspx?appid=2&r=/User/Default2.aspx");
        }
        else if (mu1.Status != 0)
        {
            function.WriteErrMsg("你的帐户未通过验证或被锁定,请与网站管理员联系", "/wxpromo.aspx?appid=2&r=/User/Default2.aspx");
        }

        if (buser.CheckLogin())
        {
            uappMod = uappBll.SelModelByUid(mu1.UserID, "wechat");
            if (uappMod != null)
            {
                M_WX_User wxuserMod = wxuserBll.SelForOpenid(2, uappMod.OpenID);
                if (wxuserMod == null)
                {
                    WxAPI   wxapi  = WxAPI.Code_Get(2);
                    string  apiurl = "https://api.weixin.qq.com/cgi-bin/";
                    string  result = APIHelper.GetWebResult(apiurl + "user/info?access_token=" + wxapi.AccessToken + "&openid=" + uappMod.OpenID);
                    JObject obj    = JsonConvert.DeserializeObject <JObject>(result);
                    if (obj["errcode"].ToString() == "40003")
                    {
                        buser.ClearCookie();
                        Response.Redirect("/wxpromo.aspx?appid=2&r=/User/Default2.aspx");
                    }
                }
            }
        }
        else if (badmin.CheckLogin())
        {
            M_AdminInfo adminMod = badmin.GetAdminLogin();
            M_UserInfo  mu       = buser.GetUserByName(adminMod.AdminName, adminMod.AdminPassword);
            if (mu == null || mu.IsNull || mu.UserID < 1)
            {
                Response.Redirect("/User/Login.aspx");
            }
            else if (mu.Status != 0)
            {
                function.WriteErrMsg("你的帐户未通过验证或被锁定,请与网站管理员联系", "/wxpromo.aspx?appid=2&r=/User/Default2.aspx");
            }
            else
            {
                buser.SetLoginState(mu);
            }
        }
        else
        {
            B_User.CheckIsLogged(Request.RawUrl);
        }
    }
Esempio n. 14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (function.isAjax())
            {
                M_APIResult result = new M_APIResult();
                result.retcode = M_APIResult.Failed;
                WxAPI  api    = WxAPI.Code_Get(AppId);
                string action = Request["action"];
                //result.result = api.AccessToken;
                //RepToClient(result);
                try
                {
                    switch (action)
                    {
                    case "create":
                        string jsondata = "{\"button\":" + Request.Form["menus"] + "}";
                        result.result = api.CreateWxMenu(jsondata);
                        if (!result.result.Contains("errmsg"))
                        {
                            result.retcode = M_APIResult.Success;
                        }
                        else
                        {
                            result.retmsg = result.result;
                        }
                        break;

                    case "get":
                        result.result = api.GetWxMenu();
                        if (!result.result.Contains("errmsg"))
                        {
                            result.retcode = M_APIResult.Success;
                        }
                        else
                        {
                            result.retmsg = result.result;
                        }
                        break;

                    default:
                        result.retmsg = "接口[" + action + "]不存在";
                        break;
                    }
                }
                catch (Exception ex) { result.retmsg = ex.Message; }
                RepToClient(result);
            }

            if (!IsPostBack)
            {
                M_WX_APPID appmod = appbll.SelReturnModel(AppId);
                string     alias  = " [公众号:" + appmod.Alias + "]";
                Call.SetBreadCrumb(Master, "<li><a href='" + CustomerPageAction.customPath2 + "Main.aspx'>工作台</a></li><li><a href='" + CustomerPageAction.customPath2 + "WeiXin/WxAppManage.aspx'>公众号管理</a></li><li class='active'>自定义菜单" + alias + "</li>");
            }
        }
Esempio n. 15
0
        public IActionResult EditWxMenu()
        {
            try { api = WxAPI.Code_Get(AppId); } catch (Exception ex) { return(WriteErr("微信公众号配置不正确," + ex.Message)); }
            if (Request.IsAjax())
            {
                M_APIResult result = new M_APIResult();
                result.retcode = M_APIResult.Failed;
                WxAPI  api    = WxAPI.Code_Get(AppId);
                string action = GetParam("action");
                //result.result = api.AccessToken;
                //RepToClient(result);
                try
                {
                    switch (action)
                    {
                    case "create":
                        string jsondata = "{\"button\":" + Request.Form["menus"] + "}";
                        result.result = api.CreateWxMenu(jsondata);
                        if (!result.result.Contains("errmsg"))
                        {
                            result.retcode = M_APIResult.Success;
                        }
                        else
                        {
                            result.retmsg = result.result;
                        }
                        break;

                    case "get":
                        result.result = api.GetWxMenu();
                        if (!result.result.Contains("errmsg"))
                        {
                            result.retcode = M_APIResult.Success;
                        }
                        else
                        {
                            result.retmsg = result.result;
                        }
                        break;

                    default:
                        result.retmsg = "接口[" + action + "]不存在";
                        break;
                    }
                }
                catch (Exception ex) { result.retmsg = ex.Message; }
                return(Content(result.ToString()));
            }
            else
            {
                return(View(viewDir + "EditWxMenu.cshtml"));
            }
        }
Esempio n. 16
0
        protected void Save_Btn_Click(object sender, EventArgs e)
        {
            List <M_WXImgItem> imgList = JsonConvert.DeserializeObject <List <M_WXImgItem> >(Article_Hid.Value);

            //替换img路径
            foreach (var item in imgList)
            {
                item.Description = htmlHelp.ConvertImgUrl(item.Description, "http://" + Request.Url.Authority);
            }
            if (!string.IsNullOrEmpty(Request.Form["appids"]))
            {
                string[] appids = Request.Form["appids"].Split(',');
                foreach (var item in appids)
                {
                    WxAPI  m_api  = WxAPI.Code_Get(Convert.ToInt32(item));
                    string result = SendImgMsg(imgList);
                    Status_Li.Text += "<dd>微信公众号:" + api.AppId.Alias + ":" + result + "</dd>";
                }
            }
            else
            {
                function.WriteErrMsg("请选择微信公众号!");
            }
            //List<M_WXNewsItem> itemList = new List<M_WXNewsItem>();
            //foreach (var item in imgList)
            //{
            //    上传文件
            //    FileInfo file = new FileInfo(function.VToP(item.PicUrl));
            //    FileStream fs = file.Open(FileMode.Open, FileAccess.Read);
            //    string media = JsonConvert.DeserializeObject<JObject>(wxBll.UploadImg(fs, Path.GetFileName(item.PicUrl)))["media_id"].ToString();//获取mediaID
            //    添加多图文信息
            //    itemList.Add(new M_WXNewsItem() { title = item.Title, digest = "描述", thumb_media_id = media, author = B_Admin.GetLogin().UserName, content = item.Description, content_source_url = "http://demo.z01.com" });
            //}
            //JObject jobj=JsonConvert.DeserializeObject<JObject>(wxBll.UploadMPNews(itemList));
            //M_WXAllMsg model = new M_WXAllMsg() { filter = new WXFiter() { group_id = "", is_to_all = true }, msgtype = "mpnews", mpnews = new M_WXMsgMedia() { media_id = jobj["media_id"].ToString() } };
            //string result = wxBll.SendAll(model);
            //jobj = JsonConvert.DeserializeObject<JObject>(result);
            //if (jobj["errcode"].ToString().Equals("0"))
            //{
            //    wxBll.GetWxConfig("sendall", DateTime.Now.ToString());
            //    function.WriteSuccessMsg("群发成功!");
            //}
            //else if (jobj["errcode"].ToString().Equals("45028"))
            //    function.WriteErrMsg("群发失败!您的微信群发次数超过上限");
            //else
            //    function.WriteErrMsg(result);
            //M_WxImgMsg msg = new M_WxImgMsg();
            //string json = Article_Hid.Value;
            //List<M_WXImgItem> itemList = JsonConvert.DeserializeObject<List<M_WXImgItem>>(Article_Hid.Value);
            //msg.Articles = itemList;
            //wxBll.SendAllBySingle(msg);
            //function.WriteSuccessMsg("图文消息发送完成");
        }
Esempio n. 17
0
 public string wxqrcode(int refereeType, string refereeId, string key)
 {
     try
     {
         if (string.IsNullOrEmpty(key))
         {
             retMod.retmsg = "未指定key";
         }
         else if (!key.Equals(APIKey))
         {
             retMod.retmsg = "key不正确";
         }
         else
         {
             int            scenceid = 0;
             B_CodeModel    codeBll  = new B_CodeModel("ZL_SSW_WXQRCode");
             SqlParameter[] sp       = new SqlParameter[] { new SqlParameter("refereeId", refereeId) };
             DataTable      dt       = codeBll.SelByWhere("refereeType=" + refereeType + " AND refereeId=" + refereeId, "ID DESC", sp);
             if (dt.Rows.Count < 1)
             {
                 DataRow dr = dt.NewRow();
                 dr["refereeType"] = refereeType;
                 dr["refereeId"]   = refereeId;
                 scenceid          = codeBll.Insert(dr);
             }
             else
             {
                 scenceid = Convert.ToInt32(dt.Rows[0]["ID"]);
             }
             //--------------------------------------------------------------------------
             WxAPI   wxapi     = WxAPI.Code_Get();
             string  resultStr = APIHelper.GetWebResult("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + wxapi.AccessToken + "&type=jsapi", "POST", "{\"expire_seconds\":604800,\"action_name\":\"QR_LIMIT_SCENE\",\"action_info\":{\"scene\":{\"scene_id\":" + scenceid + "}}}");
             JObject result    = (JObject)JsonConvert.DeserializeObject(resultStr);
             if (result["ticket"] == null)
             {
                 retMod.retmsg = resultStr; ZLLog.L("wxqrcode failed1:" + resultStr);
             }
             else
             {
                 retMod.result  = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + HttpUtility.UrlEncode(result["ticket"].ToString());
                 retMod.retcode = M_APIResult.Success;
             }
         }
     }
     catch (Exception ex)
     {
         retMod.retmsg = ex.Message;
         ZLLog.L("wxqrcode failed2:" + ex.Message);
     }
     return(retMod.ToString());
 }
Esempio n. 18
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            M_UserInfo mu    = buser.GetLogin();
            int        appid = DataConverter.CLng(Request.QueryString["appid"]);
            if (appid == 1)
            {
                footer_div1.Visible = true;
            }
            else if (appid == 2)
            {
                footer_div2.Visible = true;
            }
            else
            {
                footer_div1.Visible = true;
            }
            try
            {
                TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
                timestr = Convert.ToInt64(ts.TotalSeconds).ToString();

                WxAPI wxapi = WxAPI.Code_Get(appid);
                appMod = appBll.SelReturnModel(appid);
                string result = APIHelper.GetWebResult("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appMod.APPID + "&secret=" + appMod.Secret);
                if (result.Contains("errcode"))
                {
                    wxapi.ErroMsg(result);
                }
                //{"access_token":"7EHneznPapbfKYIQISQGVw4comvbkxIWe5e7JmTkp2Y5P93aIO5FjjEeyvk65L4lcPeL6VuMOMZ7CKel95L_ljZnjZrdi-MGPK9mZZOuSN8","expires_in":7200}
                JObject obj = JsonConvert.DeserializeObject <JObject>(result);
                appMod.Token     = obj["access_token"].ToString();
                appMod.TokenDate = DateTime.Now;
                appBll.UpdateByID(appMod);

                string  jsapi_ticket = APIHelper.GetWebResult("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + appMod.Token + "&type=jsapi");
                JObject jsapi_obj    = (JObject)JsonConvert.DeserializeObject(jsapi_ticket);
                string  stringA      = "jsapi_ticket=" + jsapi_obj["ticket"].ToString() + "&noncestr=" + nonceStr + "&timestamp=" + timestr + "&url=" + Request.Url.AbsoluteUri;
                paySign = EncryptHelper.SHA1(stringA).ToLower();

                string jsapi_ticket1 = APIHelper.GetWebResult("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + wxapi.AccessToken + "&type=jsapi", "POST", "{\"action_name\":\"QR_LIMIT_STR_SCENE\",\"action_info\":{\"scene\":{\"scene_str\":\"" + mu.UserID + "\"}}}");
                if (jsapi_ticket1 != "")
                {
                    JObject jsapi_obj1 = (JObject)JsonConvert.DeserializeObject(jsapi_ticket1);
                    Image1.ImageUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + jsapi_obj1["ticket"];
                }
            }
            catch (Exception ex) { }
        }
    }
Esempio n. 19
0
    public void WeiXinPay()
    {
        //M_OrderList orderMod = new M_OrderList();
        //orderMod = orderBll.SelModelByOrderNo(OrderNo);
        payMod = paymentBll.SelModelByPayNo(PayNo);
        //function.WriteErrMsg(DataConverter.CLng(payMod.MoneyPay * 100).ToString());
        // B_Payment payBll = new B_Payment();
        //payMod.PaymentNum = OrderNo;
        // payMod.PayNo = payBll.CreatePayNo();
        //payMod.UserID = mu.UserID;
        //payMod.Status = (int)M_Payment.PayStatus.NoPay;
        //payMod.Remark = orderMod.Ordermessage;
        //payMod.MoneyPay =Convert.ToDecimal(orderMod.Ordersamount);
        //payMod.MoneyReal = payMod.MoneyPay;
        //payMod.PaymentID = payBll.Add(payMod);

        //WXPayData签名存在但不合法,原因:金额为0
        //---------------------------------------------
        B_WX_APPID appBll = new B_WX_APPID();

        string code = Request.QueryString["code"];
        //M_WX_APPID appMod = new M_WX_APPID();//自行置入缓存,使用时取出
        //appMod.APPID = WxPayConfig.APPID;//"wx8af32f5bf73b2c81";
        //appMod.Secret = WxPayConfig.APPSECRET;//61c897f42cd3fcc1131f8f4fbafd3293
        //WxAPI wxapi = new WxAPI();
        WxAPI wxapi = WxAPI.Code_Get(1);
        //wxapi.AppId = appMod;

        string  resultStr = APIHelper.GetWebResult("https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + wxapi.AppId.APPID + "&secret=" + wxapi.AppId.Secret + "&code=" + code + "&grant_type=authorization_code");
        JObject obj       = (JObject)JsonConvert.DeserializeObject(resultStr);

        string    urlReq1 = Request.Url.AbsoluteUri.ToString().Substring(0, Request.Url.AbsoluteUri.ToString().LastIndexOf('/'));
        WxPayData wxdata  = new WxPayData();

        wxdata.SetValue("out_trade_no", payMod.PayNo);
        wxdata.SetValue("body", "我点吧");
        wxdata.SetValue("total_fee", Convert.ToInt32(payMod.MoneyPay * 100));//DataConverter.CLng(payMod.MoneyPay * 100)
        wxdata.SetValue("trade_type", "JSAPI");
        wxdata.SetValue("notify_url", urlReq1 + "/Return/WxPayReturn.aspx");
        wxdata.SetValue("product_id", payMod.PaymentNum);
        wxdata.SetValue("openid", obj["openid"].ToString());
        wxdata.SetValue("nonce_str", nonceStr);
        WxPayData result = WxPayApi.UnifiedOrder(wxdata);

        if (result.GetValue("return_code").ToString().Equals("FAIL"))
        {
            function.WriteErrMsg("商户" + result.GetValue("return_msg"));
        }
        prepay_id = result.GetValue("prepay_id").ToString();
    }
 protected void Page_Load(object sender, EventArgs e)
 {
     api = WxAPI.Code_Get(AppID);
     if (!IsPostBack)
     {
         if (string.IsNullOrEmpty(TlpID))
         {
             function.WriteErrMsg("未指定模板ID");
         }
         MyBind();
         LoadParas();
         Call.SetBreadCrumb(Master, "<li><a href='" + CustomerPageAction.customPath2 + "Main.aspx'>工作台</a></li><li><a href='" + CustomerPageAction.customPath2 + "WeiXin/WxAppManage.aspx'>公众号管理</a></li><li class='active'>模板消息</li>");
     }
 }
Esempio n. 21
0
        public IActionResult WelPage_Submit(M_WXImgItem itemMod)
        {
            M_WxImgMsg msgMod = new M_WxImgMsg();

            itemMod.PicUrl = StrHelper.UrlDeal(itemMod.PicUrl);
            itemMod.Url    = StrHelper.UrlDeal(itemMod.Url);
            msgMod.Articles.Add(itemMod);
            M_WX_APPID appmod = appBll.SelReturnModel(AppId);

            appmod.WelStr = JsonConvert.SerializeObject(msgMod);
            appBll.UpdateByID(appmod);
            WxAPI.Code_Get(appmod).AppId.WelStr = appmod.WelStr;
            return(WriteOK("操作成功", ""));
        }
Esempio n. 22
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            M_UserInfo mu    = buser.GetLogin();
            int        appid = DataConverter.CLng(Request.QueryString["appid"]);

            if (mu != null && mu.UserID > 0)
            {
                try
                {
                    TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
                    timestr = Convert.ToInt64(ts.TotalSeconds).ToString();
                    if (appid == 0)
                    {
                        appid = 1;
                    }
                    WxAPI wxapi = WxAPI.Code_Get(appid);
                    appMod = appBll.SelReturnModel(appid);

                    uappMod  = uappBll.SelModelByUid(mu.UserID, "wechat");
                    wuserMod = wxapi.GetWxUserModel(uappMod.OpenID);

                    userface.Src  = wuserMod.HeadImgUrl;
                    userface.Alt  = wuserMod.Name;
                    NickName.Text = wuserMod.Name;

                    string  jsapi_ticket = APIHelper.GetWebResult("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + wxapi.AccessToken + "&type=jsapi");
                    JObject jsapi_obj    = (JObject)JsonConvert.DeserializeObject(jsapi_ticket);
                    string  stringA      = "jsapi_ticket=" + jsapi_obj["ticket"].ToString() + "&noncestr=" + nonceStr + "&timestamp=" + timestr + "&url=" + Request.Url.AbsoluteUri;
                    paySign = EncryptHelper.SHA1(stringA).ToLower();

                    string jsapi_ticket1 = APIHelper.GetWebResult("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + wxapi.AccessToken + "&type=jsapi", "POST", "{\"action_name\":\"QR_LIMIT_STR_SCENE\",\"action_info\":{\"scene\":{\"scene_str\":\"" + mu.UserID + "\"}}}");
                    if (jsapi_ticket1 != "")
                    {
                        JObject jsapi_obj1 = (JObject)JsonConvert.DeserializeObject(jsapi_ticket1);
                        Image1.ImageUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + jsapi_obj1["ticket"];
                    }
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                Response.Redirect("/wxpromo.aspx?r=/User");
            }
        }
    }
Esempio n. 23
0
 private void SendMsg(Object info)
 {
     try
     {
         M_WxTextMsg reqMod = (M_WxTextMsg)info;
         System.Threading.Thread.Sleep(1000);//延迟1秒,避免先于欢迎消息
         M_WX_APPID appmod = new B_WX_APPID().GetAppByWxNo(reqMod.ToUserName);
         if (appmod == null)
         {
             throw new Exception("目标公众号[" + reqMod.ToUserName + "]不存在");
         }
         WxAPI.Code_Get(appmod).SendMsg(reqMod.FromUserName, "您好,欢迎关注氿度伞,成为氿度伞的用户,我们将竭诚为您服务。我们为大家提供导航借伞、还伞、转伞,圈子社交等服务。24小时免费用伞,倡导绿色出行。转伞一人,即得5元。氿度伞欢迎您的使用!祝您用伞愉快!");
     }
     catch (Exception ex) { ZLLog.L("微信多信息出错,原因:" + ex.Message); }
 }
Esempio n. 24
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                WxAPI  wxapi = WxAPI.Code_Get();
                string code  = Request.QueryString["code"] ?? "";
                if (string.IsNullOrEmpty(code))
                {
                    return;
                }
                string     result = APIHelper.GetWebResult("https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + wxapi.AppId.APPID + "&secret=" + wxapi.AppId.Secret + "&code=" + code + "&grant_type=authorization_code");
                JObject    obj    = (JObject)JsonConvert.DeserializeObject(result);
                string     openid = obj["openid"].ToString();
                Appinfo    umod   = appBll.SelModelByOpenID(openid, "wechat");
                M_UserInfo mu     = new M_UserInfo();
                if (umod == null)
                {
                    umod = new Appinfo();
                    M_WX_User wuMod = wxuserBll.SelForOpenid(wxapi.AppId.ID, openid);
                    if (wuMod == null)
                    {
                        wuMod = wxapi.GetWxUserModel(openid);
                        wxuserBll.Insert(wuMod);
                    }
                    mu.UserName  = "******" + DateTime.Now.ToString("yyyyMMddHHmmss") + function.GetRandomString(2).ToLower();
                    mu.UserPwd   = StringHelper.MD5(function.GetRandomString(6));
                    mu.Email     = function.GetRandomString(10) + "@random.com";
                    mu.HoneyName = wuMod.Name;
                    mu.TrueName  = wuMod.Name;
                    mu.UserID    = buser.Add(mu);

                    umod.UserID     = mu.UserID;
                    umod.SourcePlat = "wechat";
                    umod.OpenID     = wuMod.OpenID;
                    appBll.Insert(umod);
                    M_Uinfo mubase = new M_Uinfo();
                    mubase.UserId = mu.UserID;
                    buser.AddBase(mubase);
                }
                else
                {
                    mu = buser.SelReturnModel(umod.UserID);
                }
                //设置为登录状态
                buser.SetLoginState(mu);
                Response.Redirect(RUrl);
            }
        }
Esempio n. 25
0
    //<li><a href="/Admin/Main.aspx">工作台</a></li><li><a href="/Admin/WeiXin/Default.aspx">微信管理</a></li><li class="active">微信发送</li>
    protected void Save_Btn_Click(object sender, EventArgs e)
    {
        M_WXImgItem itemMod = new M_WXImgItem()
        {
            Title = Title_T.Text, Description = Content_T.Text
        };

        itemMod.PicUrl = StrHelper.UrlDeal(PicUrl_T.Text);
        itemMod.Url    = StrHelper.UrlDeal(Url_T.Text);
        msgMod.Articles.Add(itemMod);
        M_WX_APPID appmod = ExHelper.WX_SelMyModel();

        appmod.WelStr = JsonConvert.SerializeObject(msgMod);
        appBll.UpdateByID(appmod);
        WxAPI.Code_Get(appmod).AppId.WelStr = appmod.WelStr;
        function.WriteSuccessMsg("修改成功");
    }
Esempio n. 26
0
        /// <summary>
        /// 获取公众号配置信息,默认读取配置文件
        /// </summary>
        /// <param name="appid"></param>
        /// <returns></returns>
        public static M_WX_APPID Pay_GetByID(int appid = 0)
        {
            M_WX_APPID appMod = new M_WX_APPID();

            if (appid > 0)
            {
                appMod = WxAPI.Code_Get(appid).AppId;
            }
            else
            {
                appMod               = WxAPI.Code_Get().AppId;
                appMod.Pay_APPID     = WxPayConfig.APPID;
                appMod.Pay_AccountID = WxPayConfig.MCHID;
                appMod.Pay_Secret    = WxPayConfig.APPSECRET;
                appMod.Pay_Key       = WxPayConfig.KEY;
            }
            return(appMod);
        }
Esempio n. 27
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ExHelper.CheckUserAuth("wechat");
        M_CommonData storeMod = ExHelper.Store2_User();

        if (DataConverter.CLng(storeMod.SpecialID) < 1)
        {
            function.WriteErrMsg("尚未绑定微信号", "/Extend/WX/WXConfig.aspx");
        }
        AppId = Convert.ToInt32(storeMod.SpecialID);
        api   = WxAPI.Code_Get(AppId);

        if (function.isAjax())
        {
            string action = Request.Form["action"]; string result = "";
            switch (action)
            {
            case "update":
                M_WX_User oldmod = wxuserBll.SelForOpenid(Request.Form["openid"]);
                if (oldmod != null && oldmod.ID > 0)
                {
                    M_WX_User usermod = api.GetWxUserModel(Request.Form["openid"]);
                    usermod.ID    = oldmod.ID;
                    usermod.CDate = DateTime.Now;
                    usermod.AppId = api.AppId.ID;
                    wxuserBll.UpdateByID(usermod);
                    result = JsonConvert.SerializeObject(usermod);
                }
                else
                {
                    result = "-1";
                }
                break;

            default:
                break;
            }
            Response.Write(result); Response.Flush(); Response.End();
        }
        if (!IsPostBack)
        {
            MyBind();
        }
    }
 //获取图片与图文数据
 public string GetConfigData(DataTable dt)
 {
     if (AppId > 0)
     {
         return(GetMeterialData());
     }
     foreach (DataRow item in dt.Rows)
     {
         api = WxAPI.Code_Get(Convert.ToInt32(item["ID"]));
         string result = GetMeterialData();
         if (result.Contains("errcode"))
         {
             continue;
         }
         AppId = api.AppId.ID;
         return(result);
     }
     function.WriteErrMsg("请添加有效的微信公众号!");
     return("");
 }
Esempio n. 29
0
    protected void GetHeadImg(M_UserInfo mu)
    {
        int appid = 1;

        if (AppID > 0)
        {
            appid = AppID;
        }
        WxAPI wxapi = WxAPI.Code_Get(appid);

        if (mu == null || mu.IsNull || mu.UserID < 1)
        {
        }
        else
        {
            uappMod = uappBll.SelModelByUid(mu.UserID, "wechat");
            M_WX_User wuserMod = new M_WX_User();
            if (uappMod != null)
            {
                try
                {
                    wuserMod = wxapi.GetWxUserModel(uappMod.OpenID);
                    if (string.IsNullOrEmpty(wuserMod.Name))
                    {
                        wxapi.GetToken();
                        wuserMod = wxapi.GetWxUserModel(uappMod.OpenID);
                    }
                }
                catch (Exception ex)
                {
                    wxapi.GetToken();
                    wuserMod = wxapi.GetWxUserModel(uappMod.OpenID);
                    throw ex;
                }
                if (wuserMod != null)
                {
                    Response.Write("{\"nickname\":\"" + wuserMod.Name + "\",\"headimgurl\":\"" + wuserMod.HeadImgUrl + "\"}");
                }
            }
        }
    }
        public WxPayData OrderQuery(WxPayData inputObj, int timeOut = 6)
        {
            M_WX_APPID appMod = WxAPI.Code_Get().AppId;//默认取第一个,如有多个的话,请按需修改
            string     url    = "https://api.mch.weixin.qq.com/pay/orderquery";

            //检测必填参数
            if (!inputObj.IsSet("out_trade_no") && !inputObj.IsSet("transaction_id"))
            {
                throw new WxPayException("订单查询接口中,out_trade_no、transaction_id至少填一个!");
            }
            inputObj.SetValue("appid", appMod.Pay_APPID);                            //公众帐号ID
            inputObj.SetValue("mch_id", appMod.Pay_AccountID);                       //商户号
            inputObj.SetValue("nonce_str", WxAPI.nonce);                             //随机字符串
            inputObj.SetValue("sign", inputObj.MakeSign());                          //签名
            string    xml      = inputObj.ToXml();
            string    response = HttpService.Post(xml, url, false, timeOut, appMod); //调用HTTP通信接口提交数据
            WxPayData result   = GetWxDataMod();

            result.FromXml(response);
            return(result);
        }