Example #1
0
        public bool SendWeiXinCustomerNote(WeiXinCustomerEntity customer)
        {
            bool   success = false;
            string url     = string.Format(WeiXinConfig.Customer_Format_Send, WeiXinJsSdk.Instance.GetAccessToken(false));

            string           json     = JsonJC.ObjectToJson(customer);
            string           result   = WebServiceClient.QueryPostWebServiceJson(url, json);
            WeiXinFailEntity resulten = JsonJC.JsonToObject <WeiXinFailEntity>(result);
            ///发送微信备案
            WeChatMsgEntity msg = new WeChatMsgEntity();

            msg.ParamStr     = json;
            msg.WeChatOpenId = "";
            msg.RedirectUrl  = "";
            msg.WeChatUrl    = url;
            msg.TemplateIid  = "";
            msg.Result       = result;
            msg.Id           = WeChatMsgBLL.Instance.AddWeChatMsg(msg);
            if (resulten.errmsg.ToLower() == "ok")
            {
                success = true;
            }
            return(success);
        }
Example #2
0
        /// <summary>
        /// 发送微信通知
        /// </summary>
        /// <param name="WeChatUnionId"></param>
        /// <param name="redirecturl"></param>
        /// <param name="templetid"></param>
        /// <param name="hashen"></param>
        /// <returns></returns>

        public bool SendWeiXinMsgNote(string WeChatUnionId, string redirecturl, string templetid, Hashtable hashen)
        {
            bool success = false;
            //获取链接导航Id
            //int navid = WeChatNavigationBLL.Instance.GetIdByUrl(redirecturl);
            MemWeChatMsgEntity wecharmsg = MemWeChatMsgBLL.Instance.GetMsgByAppUnionId(WeiXinConfig.GetAppId(), WeChatUnionId);

            if (wecharmsg != null && !string.IsNullOrEmpty(wecharmsg.OpenId))
            {
                WeiXinSendMsgEntity send = new WeiXinSendMsgEntity();
                send.touser      = wecharmsg.OpenId;
                send.template_id = templetid;
                string resulturl = string.Format(WeiXinConfig.URL_WeiXin_Redirect, WeiXinConfig.GetAppId(), System.Web.HttpContext.Current.Server.UrlEncode(redirecturl), "0");
                send.url  = resulturl;
                send.data = hashen;
                string json = JsonJC.ObjectToJson(send);
                string url  = string.Format(WeiXinConfig.URL_FORMAT_SendMsg, WeiXinJsSdk.Instance.GetAccessToken(false));
                ///发送微信备案
                WeChatMsgEntity msg = new WeChatMsgEntity();
                msg.ParamStr     = json;
                msg.WeChatOpenId = wecharmsg.OpenId;
                msg.RedirectUrl  = redirecturl;
                msg.WeChatUrl    = url;
                msg.TemplateIid  = templetid;
                msg.Id           = WeChatMsgBLL.Instance.AddWeChatMsg(msg);
                string           result   = WebServiceClient.QueryPostWebServiceJson(url, json);
                WeiXinFailEntity resulten = JsonJC.JsonToObject <WeiXinFailEntity>(result);
                msg.Result = result;
                WeChatMsgBLL.Instance.UpdateWeChatMsg(msg);
                if (resulten.errmsg.ToLower() == "ok")
                {
                    success = true;
                }
                else if (resulten.errcode == "40001" && resulten.errmsg.Contains("access_token is invalid or not latest hint"))
                {
                    ///发现accesstoken过期后再次发送
                    WeiXinJsSdk.Instance.RemoveAccessToken();
                    url = string.Format(WeiXinConfig.URL_FORMAT_SendMsg, WeiXinJsSdk.Instance.GetAccessToken(false));
                    ///发送微信备案
                    msg.WeChatUrl = url;
                    msg.Result    = "";
                    msg.Id        = 0;
                    msg.Id        = WeChatMsgBLL.Instance.AddWeChatMsg(msg);
                    result        = WebServiceClient.QueryPostWebServiceJson(url, json);
                    resulten      = JsonJC.JsonToObject <WeiXinFailEntity>(result);
                    msg.Result    = result;
                    WeChatMsgBLL.Instance.UpdateWeChatMsg(msg);
                    if (resulten.errmsg.ToLower() == "ok")
                    {
                        success = true;
                    }
                    else
                    {
                        //需发邮件提醒
                        EmailSendBLL.Instance.WeiXinSendFail(WeChatUnionId, redirecturl);
                    }
                }
                else
                {
                    //需发邮件提醒
                    EmailSendBLL.Instance.WeiXinSendFail(WeChatUnionId, redirecturl);
                }
            }
            return(success);
        }
Example #3
0
        /// <summary>
        /// 询价订单供应商发送微信提醒
        /// </summary>
        /// <returns></returns>
        public string WeChatInquiryOrderSend()
        {
            ResultObj result    = new ResultObj();
            string    ordercode = FormString.SafeQ("ordercode");
            string    memids    = FormString.SafeQ("memids");

            memids = memids.Trim(',');

            string[] memidattr = memids.Split(',');

            InquiryOrderEntity orderentity = InquiryOrderBLL.Instance.GetInquiryOrderByCode(ordercode);

            if (orderentity != null && orderentity.Status == (int)OrderInquiryStatusEnum.Quoting)
            {
                string url         = string.Format(WeiXinConfig.URL_FORMAT_SendMsg, WeiXinJsSdk.Instance.GetAccessToken());
                string resulturl   = SuperMarketWebUrl.InquiryOrderSendWeChat(ordercode);
                string redirecturl = SuperMarketWebUrl.InquiryOrderUrl(ordercode);
                result.Obj = resulturl;
                ////获取链接导航Id
                //int navid = WeChatNavigationBLL.Instance.GetIdByUrl(redirecturl);
                foreach (string memidstr in memidattr)
                {
                    int          memid = StringUtils.GetDbInt(memidstr);
                    MemberEntity memen = MemberBLL.Instance.GetMember(memid);
                    if (!string.IsNullOrEmpty(memen.WeChat))
                    {
                        MemWeChatMsgEntity wecharmsg = MemWeChatMsgBLL.Instance.GetMsgByAppUnionId(WeiXinConfig.GetAppId(), memen.WeChat);
                        if (wecharmsg != null && !string.IsNullOrEmpty(wecharmsg.OpenId))
                        {
                            WeiXinSendMsgEntity send = new WeiXinSendMsgEntity();
                            send.touser      = wecharmsg.OpenId;
                            send.template_id = WeiXinTemplet.InquiryQuoteSend;
                            send.url         = resulturl;
                            WeiXinInquiryEntity inq = new WeiXinInquiryEntity();
                            inq.first = new WeiXinUnitEntity()
                            {
                                value = "您有订单需要报价啦,赶紧抢单,订单编号:" + orderentity.Code
                            };
                            inq.tradeDateTime = new WeiXinUnitEntity()
                            {
                                value = orderentity.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                            };
                            inq.orderType = new WeiXinUnitEntity()
                            {
                                value = "询价订单"
                            };
                            inq.customerInfo = new WeiXinUnitEntity()
                            {
                                value = "易店心"
                            };
                            //inq.orderItemName = new WeiXinUnitEntity() { value = "随机名称" };
                            //inq.orderItemData = new WeiXinUnitEntity() { value = "随机数据" };
                            inq.remark = new WeiXinUnitEntity()
                            {
                                value = orderentity.Remark
                            };
                            send.data = inq;
                            string          json = JsonJC.ObjectToJson(send);
                            WeChatMsgEntity msg  = new WeChatMsgEntity();
                            msg.ParamStr     = json;
                            msg.WeChatOpenId = wecharmsg.OpenId;
                            msg.RedirectUrl  = redirecturl;
                            msg.WeChatUrl    = url;
                            msg.TemplateIid  = WeiXinTemplet.InquiryQuoteSend;
                            msg.Id           = WeChatMsgBLL.Instance.AddWeChatMsg(msg);
                            string           resultrowi = WebServiceClient.QueryPostWebServiceJson(url, json);
                            WeiXinFailEntity resulten   = JsonJC.JsonToObject <WeiXinFailEntity>(resultrowi);
                            if (resulten.errmsg.ToLower() == "ok")
                            {
                                CGMemQuotedBLL.Instance.CGQuotedSend(memid, ordercode);
                            }
                            msg.Result = resultrowi;
                            WeChatMsgBLL.Instance.UpdateWeChatMsg(msg);
                        }
                    }
                }
            }
            else
            {
                CGMemQuotedBLL.Instance.QuotedCloseByCode(ordercode);
            }
            result.Status = (int)CommonStatus.Success;
            return(JsonJC.ObjectToJson(result));
        }