示例#1
0
        public JsonResult ReplyTopic(TopicDetailModel model)
        {
            JsonModel jm = new JsonModel();

            try
            {
                int CurrentUserId = GetCurrentUser().Id;
                IPostBarTopicDiscussBLL replyTopicBLL = BLLFactory <IPostBarTopicDiscussBLL> .GetBLL("PostBarTopicDiscussBLL");

                var replyTopic = new T_PostBarTopicDiscuss()
                {
                    Content    = model.ReplyTopicContent,
                    ReplyId    = model.PostUserId,
                    PostUserId = CurrentUserId,
                    PostTime   = DateTime.Now,
                    TopicId    = model.Id
                };

                //图片上传
                if (!string.IsNullOrEmpty(model.ReplyTopicImgList))
                {
                    //图片集路径保存
                    replyTopic.ImgPath = GetMultimedia(ConstantParam.TOPIC_DIR, model.ReplyTopicImgList);

                    StringBuilder imgsSB = new StringBuilder();
                    //生成缩略图保存
                    foreach (var path in replyTopic.ImgPath.Split(';'))
                    {
                        string thumpFile = DateTime.Now.ToFileTime() + ".jpg";
                        string thumpPath = Path.Combine(Server.MapPath(ConstantParam.Topic_ThumPictures_DIR + model.PropertyPlaceId), thumpFile);
                        PropertyUtils.getThumImage(Path.Combine(Server.MapPath(path)), 18, 3, thumpPath);
                        imgsSB.Append(ConstantParam.Topic_ThumPictures_DIR + model.PropertyPlaceId + "/" + thumpFile + ";");
                    }

                    replyTopic.ImgThumbnail = imgsSB.ToString();
                    replyTopic.ImgThumbnail = replyTopic.ImgThumbnail.Substring(0, replyTopic.ImgThumbnail.Length - 1);
                }

                replyTopicBLL.Save(replyTopic);
            }
            catch (Exception ex)
            {
                jm.Msg = "回复主题失败";
                PubFunction.ErrorLogPrint("话题圈回复错误:", ex.ToString());
            }

            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        /// <summary>
        /// 下载保存多媒体文件,返回多媒体保存路径
        /// </summary>
        /// <param name="dirPath">下载文件保存目录</param>
        /// <param name="MEDIA_ID">多媒体文件服务器标识</param>
        /// <returns>下载的文件路径,用;分割</returns>
        public string GetMultimedia(string dirPath, string MEDIA_ID)
        {
            //目录创建
            string dir = Server.MapPath(dirPath);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            string ACCESS_TOKEN = GetTokenUtils.GetToken();
            string file         = string.Empty;

            string[] MEDIA_IDs = MEDIA_ID.Split(',');
            for (int i = 0; i < MEDIA_IDs.Length; i++)
            {
                string content  = string.Empty;
                string strpath  = string.Empty;
                string savepath = string.Empty;
                string stUrl    = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" + ACCESS_TOKEN + "&media_id=" + MEDIA_IDs[i];

                WebClient mywebclient = new WebClient();
                string    imgFileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + (new Random()).Next().ToString().Substring(0, 4) + ".jpg";
                savepath = Path.Combine(dir, imgFileName);
                try
                {
                    mywebclient.DownloadFile(stUrl, savepath);
                    file += dirPath + imgFileName + ";";
                }
                catch (Exception ex)
                {
                    PubFunction.ErrorLogPrint("服务器下载图片发生异常:", ex.ToString());
                }
            }
            file = file.Substring(0, file.Length - 1);
            return(file);
        }
示例#3
0
        /// <summary>
        /// Post请求 订单申请退款
        /// </summary>
        /// <returns></returns>
        private string ApplyRefund(T_Order order, string WeixinAppId, string WeixinMchId, string WeixinPayKey)
        {
            Random r = new Random();

            #region 组装参数
            //组装签名字符串
            StringBuilder signStr = new StringBuilder();
            //组装xml格式
            StringBuilder varBody = new StringBuilder();

            varBody.Append("<xml>");
            //APP应用ID
            varBody.Append("<appid>" + WeixinAppId + "</appid>");
            signStr.Append("appid=" + WeixinAppId + "&");
            //商户号
            varBody.Append("<mch_id>" + WeixinMchId + "</mch_id>");
            signStr.Append("mch_id=" + WeixinMchId + "&");
            //随机字符串
            string str       = "1234567890abcdefghijklmnopqrstuvwxyz";
            string randomStr = "";
            for (int i = 0; i < 32; i++)
            {
                randomStr = randomStr + str[r.Next(str.Length)].ToString();
            }
            varBody.Append("<nonce_str>" + randomStr + "</nonce_str>");
            signStr.Append("nonce_str=" + randomStr + "&");
            //操作员
            varBody.Append("<op_user_id>" + WeixinMchId + "</op_user_id>");
            signStr.Append("op_user_id=" + WeixinMchId + "&");
            //商户退款单号
            string refundNo = DateTime.Now.ToFileTime().ToString() + new Random().Next(1000);
            varBody.Append("<out_refund_no>" + refundNo + "</out_refund_no>");
            signStr.Append("out_refund_no=" + refundNo + "&");
            //商户订单号
            varBody.Append("<out_trade_no>" + order.PayTradeNo + "</out_trade_no>");
            signStr.Append("out_trade_no=" + order.PayTradeNo + "&");

            int fee = Convert.ToInt32(order.OrderPrice * 100);
            //退款金额
            varBody.Append("<refund_fee>" + fee + "</refund_fee>");
            signStr.Append("refund_fee=" + fee + "&");
            //总金额
            varBody.Append("<total_fee>" + fee + "</total_fee>");
            signStr.Append("total_fee=" + fee + "&");
            //签名
            signStr.Append("key=" + WeixinPayKey);
            varBody.Append("<sign>" + PropertyUtils.GetMD5Str(signStr.ToString()).ToUpper() + "</sign>");
            varBody.Append("</xml>");
            #endregion
            //发送HTTP POST请求
            string url = "https://api.mch.weixin.qq.com/secapi/pay/refund";

            string cert     = Server.MapPath("~/App_Data/apiclient_cert.p12");
            string password = WeixinMchId;
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);

            X509Certificate cer     = new X509Certificate(cert, password);
            HttpWebRequest  request = (HttpWebRequest)WebRequest.Create(url);
            request.Method      = "POST";
            request.ContentType = "text/xml";
            request.ClientCertificates.Add(cer);

            byte[] bytes = Encoding.UTF8.GetBytes(varBody.ToString());
            request.ContentLength = bytes.Length;
            using (Stream writer = request.GetRequestStream())
            {
                writer.Write(bytes, 0, bytes.Length);
                writer.Flush();
                writer.Close();
            }
            //处理返回结果
            string          result   = null;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            if (response.StatusCode == HttpStatusCode.OK)
            {
                using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                {
                    result = reader.ReadToEnd();
                    reader.Close();
                }
            }
            PubFunction.ErrorLogPrint("result", result);
            return(result);
        }