Пример #1
0
        public ActionResult TemplateSend()
        {
            JsonSMsg    rMsg       = new JsonSMsg();
            string      json       = string.Empty;
            string      responjson = string.Empty;
            HttpRequest request    = HttpContext.ApplicationInstance.Context.Request;
            Stream      stream     = request.InputStream;

            if (stream.Length > 0)
            {
                StreamReader reader = new StreamReader(stream);
                json = reader.ReadToEnd();
            }
            responjson = WXMPClientServiceApi.Create().SendTemplateMsg(new WeiPage().Token(AppConfig.FWHOriginalID), json);
            if (responjson.Length > 0)
            {
                rMsg.Status  = 1;
                rMsg.Message = "成功";
                rMsg.Data    = responjson;
            }
            else
            {
                rMsg.Status  = 0;
                rMsg.Message = "失败";
            }
            return(Json(rMsg));
        }
Пример #2
0
        public List <EMPLOYEE> QueryAllEmpWithNoQrCode(string access_token)
        {
            var list = _empRepo.QueryAllNoQrCode();

            if (list != null && list.Count > 0)
            {
                foreach (var item in list)
                {
                    int ewmId = 0;
                    if (item.EwmId.HasValue)
                    {
                        ewmId = item.EwmId.Value;
                    }
                    else
                    {
                        ewmId = _systemRepo.GetEwmId() + 1;
                    }
                    item.EwmId = ewmId;
                    QRCodeResponse qrCodeResponse = WXMPClientServiceApi.Create().CreateQRCode(access_token, ewmId);
                    if (qrCodeResponse != null && qrCodeResponse.ErrorCode == 0)
                    {
                        string ticket = qrCodeResponse.Ticket;
                        item.EwmUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + qrCodeResponse.Ticket;
                    }
                    item.FullUpdate = false;

                    _empRepo.Update(item);
                }
            }

            return(list);
        }
Пример #3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (GetQeuryString("appid", context) != "")
            {
                string json       = string.Empty;
                string responjson = string.Empty;
                string errorMsg   = "";
                string appid_s    = GetQeuryString("appid", context);
                string timestamp  = GetQeuryString("timestamp", context);
                string sign       = GetQeuryString("sign", context);

                if (Auth(appid_s, timestamp, sign, context.Request.UserHostAddress, out errorMsg))
                {
                    HttpRequest request = context.Request;
                    Stream      stream  = request.InputStream;

                    if (stream.Length > 0)
                    {
                        StreamReader reader = new StreamReader(stream);
                        json = reader.ReadToEnd();
                    }
                    responjson = WXMPClientServiceApi.Create().SendTemplateMsg(new WeiPage().Token("gh_7bcc17156676"), json);
                    context.Response.Write(responjson);
                }
                else
                {
                    context.Response.Write(" { \"errcode\":1, \"errmsg\":\"" + errorMsg + "\"}");
                }
            }
            else
            {
                context.Response.Write(" { \"errcode\":1, \"errmsg\":\"appid不能为空!\" }");
            }
        }
Пример #4
0
        public ActionResult CreateEwm(int id)
        {
            WeiPage wp      = new WeiPage();
            string  mpToken = wp.Token(AppConfig.FWHOriginalID);

            string         url            = "";
            QRCodeResponse qrCodeResponse = WXMPClientServiceApi.Create().CreateQRCode(mpToken, id);

            if (qrCodeResponse != null)
            {
                url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + qrCodeResponse.Ticket;
            }

            return(Content(string.Format("EwmId:{0},EwmUrl:{1}", id, url)));
        }
Пример #5
0
        public ActionResult SaveEmployee(EMPLOYEE_MODEL model, FormCollection form)
        {
            JsonSMsg rMsg = new JsonSMsg();

            string accessToken = HmjClientServiceApi.Create().GetAccessToken();

            if (model.ID == 0)
            {
                WeiPage wp      = new WeiPage();
                string  mpToken = wp.Token(AppConfig.FWHOriginalID);
                int     ewmId   = SystemService.GetEwmId() + 1;
                model.EwmId = ewmId;
                QRCodeResponse qrCodeResponse = WXMPClientServiceApi.Create().CreateQRCode(mpToken, ewmId);
                if (qrCodeResponse != null && qrCodeResponse.ErrorCode == 0)
                {
                    model.EwmUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + qrCodeResponse.Ticket;
                }
                else
                {
                    rMsg.Message = "获取服务号access_token失败,请重试。";
                    return(Json(rMsg));
                }
            }
            DeptInfo dept = new DeptInfo();

            dept.ID = model.EmpGroupId;
            string errMsg = null;
            int    rows   = EmployeeService.SaveEmployee(accessToken, model, dept, ref errMsg);

            if (rows > 0)
            {
                rMsg.Status = 1;
            }
            else
            {
                if (string.IsNullOrEmpty(errMsg))
                {
                    errMsg = "保存失败。";
                }
                rMsg.Message = errMsg;
            }

            return(Json(rMsg));
        }
Пример #6
0
        public ActionResult SendImage()
        {
            JsonSMsg rMsg = new JsonSMsg();

            try
            {
                int        ar_id     = SystemService.GetMaxArid() + 1;
                string     file_path = "";
                string     expire    = AppConfig.ExpireAr;//该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。
                AR_QR_FANS ar        = new AR_QR_FANS();
                //获取图片流存到本地
                file_path = GetImageStreem();
                //上传本地图片到微信服务器

                string    url   = string.Format("http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token={0}&type={1}", new WeiPage().Token(AppConfig.FWHOriginalID), "image");
                string    json  = Utility.HttpUploadFile(url, file_path);
                mediainfo media = JsonConvert.DeserializeObject <mediainfo>(json);
                //删除临时图片
                if (media != null)
                {
                    System.IO.File.Delete(file_path);
                }
                //获取临时二维码
                QRCodeResponse respons = WXMPClientServiceApi.Create().CreateTempQRCode(new WeiPage().Token(AppConfig.FWHOriginalID), ar_id, expire);
                string         qr_url  = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + respons.Ticket;

                //保存到数据库
                //AR_QR_FANS arinfo = SystemService.QueryArInfoByArId(ar_id);
                //if (arinfo != null)
                //{
                //    ar = arinfo;
                //}
                ar.AR_ID          = ar_id;
                ar.AR_URL         = qr_url;
                ar.MEDIA_ID       = media.media_id;
                ar.EXPIRE_SECONDS = int.Parse(expire);
                ar.CREATE_DATE    = DateTime.Now;

                int res = SystemService.SaveArInfo(ar);
                if (res > 0)
                {
                    arinfo ars = new arinfo();
                    ars.id       = res;
                    ars.url      = qr_url;
                    rMsg.Status  = 1;
                    rMsg.Message = "成功";
                    rMsg.Data    = res + "|" + qr_url;
                }
                else
                {
                    rMsg.Status  = 0;
                    rMsg.Message = "失败";
                }
            }
            catch (Exception ex)
            {
                rMsg.Status  = 0;
                rMsg.Message = "SendImage报错:" + ex.Message;
            }
            return(Json(rMsg));
        }