コード例 #1
0
        public RetMessage <string> ogenroll()
        {
            RetMessage <string> rm = new RetMessage <string>();
            string tokenId         = "";

            try
            {
                tokenId = HttpContext.Current.Request["tokenId"];
            }
            catch
            {
                rm.RetCode  = 98;
                rm.ErrorMsg = ut.getErrMessage(rm.RetCode);
                return(rm);
            }

            string userid = ut.getUserIDByToken_og(tokenId);

            if (userid == null)
            {
                rm.RetCode  = 99;
                rm.ErrorMsg = ut.getErrMessage(rm.RetCode);
                return(rm);
            }

            HttpFileCollection files   = HttpContext.Current.Request.Files;
            string             fileurl = "";

            foreach (string f in files.AllKeys)
            {
                HttpPostedFile file = files[f];
                fileurl = file.FileName;

                if (string.IsNullOrEmpty(file.FileName) == false)
                {
                    file.SaveAs(HttpContext.Current.Server.MapPath("~/App_Data/") + file.FileName);
                }
            }
            int ogquestionnaireID = 0;

            using (organizeEntities db = new organizeEntities())
            {
                ogquestionnaire cc = new ogquestionnaire();
                cc.name         = HttpContext.Current.Request["name"].ToString();
                cc.birthday     = HttpContext.Current.Request["birthday"].ToString();
                cc.sex          = HttpContext.Current.Request["sex"].ToString();
                cc.nativeplace  = HttpContext.Current.Request["nativeplace"].ToString();
                cc.nations      = HttpContext.Current.Request["nations"].ToString();
                cc.level        = HttpContext.Current.Request["level"].ToString();
                cc.identitycard = HttpContext.Current.Request["identitycard"].ToString();
                cc.educated     = HttpContext.Current.Request["educated"].ToString();
                cc.unit         = HttpContext.Current.Request["unit"].ToString();
                cc.address      = HttpContext.Current.Request["address"].ToString();
                cc.mobile       = HttpContext.Current.Request["mobile"].ToString();
                cc.membersflag  = int.Parse(HttpContext.Current.Request["membersflag"].ToString());
                cc.place        = HttpContext.Current.Request["place"].ToString();
                cc.qqid         = HttpContext.Current.Request["qqid"].ToString();
                cc.picurl       = fileurl;
                cc.userid       = userid;
                db.ogquestionnaire.Add(cc);
                db.SaveChanges();
                ogquestionnaireID = cc.qid;
            }

            List <string> ListRetArrys = new List <string>();

            ListRetArrys.Add(ogquestionnaireID.ToString());
            rm.data    = ListRetArrys;
            rm.RetCode = 0;
            return(rm);
        }
コード例 #2
0
        public RetMessage <Order> makeOrder(string tokenId, int dataId)
        {
            RetMessage <Order> rm = new RetMessage <Order>();

            if (tokenId != null)
            {
                string useridandopenid = ut.getUserIDAndOpenIDByToken_og(tokenId);


                if (useridandopenid == null)
                {
                    //错误返回;
                    rm.RetCode  = -7;
                    rm.ErrorMsg = ut.getErrMessage(rm.RetCode);
                }
                else
                {
                    string[] buff      = useridandopenid.Split('|');
                    string   userid    = buff[0];
                    string   openid    = buff[1];
                    string   strcode   = null;
                    string   total_fee = null;
                    using (organizeEntities db = new organizeEntities())
                    {
                        //取资料主档信息
                        ogquestionnaire cc = new  ogquestionnaire();
                        cc = db.ogquestionnaire.Find(dataId);
                        if (cc == null)
                        {
                            rm.RetCode  = -6;
                            rm.ErrorMsg = ut.getErrMessage(rm.RetCode);
                            return(rm);
                        }
                        string[] levelBuff = cc.level.Split(',');
                        strcode   = "全国BIM等级考试缴费[" + cc.level + "]";
                        total_fee = (int.Parse(ut.getAppSetting(13)) * levelBuff.Count() * 100).ToString();
                    }
                    string wx_appid        = ut.getAppSetting(11);
                    string wx_mch_id       = ut.getAppSetting(1);
                    string wx_nonce_str    = ut.getRandomString(20);
                    byte[] buffer          = Encoding.UTF8.GetBytes(strcode);
                    string wx_body         = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
                    string wx_out_trade_no = DateTime.Now.ToString("yyyyMMddHHmmss") + ut.getRandomString(10);
                    string wx_total_fee    = ((int)(decimal.Parse(total_fee))).ToString();//unit:fen
                    //string wx_total_fee = "1";//unit:fen
                    //string wx_spbill_create_ip = GetWebClientIp();
                    //string wx_spbill_create_ip = "59.110.164.24";
                    string wx_spbill_create_ip = ut.getAppSetting(4);
                    string wx_notify_url       = ut.getAppSetting(3);
                    string wx_trade_type       = ut.getAppSetting(5);
                    var    dic = new Dictionary <string, string> {
                        { "appid", wx_appid },
                        { "body", wx_body },
                        { "mch_id", wx_mch_id },
                        { "nonce_str", wx_nonce_str },
                        { "notify_url", wx_notify_url },
                        { "openid", openid },
                        { "out_trade_no", wx_out_trade_no },
                        { "spbill_create_ip", wx_spbill_create_ip },
                        { "total_fee", wx_total_fee },
                        { "trade_type", wx_trade_type }
                    };
                    dic.Add("sign", ut.GetSignString(dic));
                    var sb = new StringBuilder();
                    sb.Append("<xml>");
                    foreach (var d in dic)
                    {
                        sb.Append("<" + d.Key + ">" + d.Value + "</" + d.Key + ">");
                    }
                    sb.Append("</xml>");
                    string       response = ut.CreatedPostHttpResponse("https://api.mch.weixin.qq.com/pay/unifiedorder", sb);
                    byte[]       array    = Encoding.UTF8.GetBytes(response);
                    MemoryStream ms       = new MemoryStream(array);
                    StreamReader sr       = new StreamReader(ms);
                    string       html     = sr.ReadToEnd();
                    var          xml      = new XmlDocument();
                    xml.LoadXml(response);
                    var                 root   = xml.DocumentElement;
                    StringReader        stram  = new StringReader(html);
                    XmlTextReader       reader = new XmlTextReader(stram);
                    System.Data.DataSet ds     = new System.Data.DataSet();
                    ds.ReadXml(reader);
                    string return_code = ds.Tables[0].Rows[0]["return_code"].ToString();
                    if (return_code.ToUpper() == "SUCCESS")
                    {
                        using (organizeEntities db = new organizeEntities())
                        {
                            string  strNow = DateTime.Now.ToString("u");
                            payinfo pi     = new payinfo();
                            pi.dataid  = dataId;
                            pi.paydate = strNow.Substring(0, 10);
                            pi.paytime = strNow.Substring(10, 8);
                            //(int)decimal.Parse(total_fee)*100
                            pi.paymount     = total_fee;//total_fee
                            pi.out_trade_no = wx_out_trade_no;
                            pi.userid       = userid;
                            db.payinfo.Add(pi);
                            db.SaveChanges();
                        }
                        //wx_out_trade_no
                        var res = new Dictionary <string, string> {
                            { "appID", wx_appid },
                            { "nonceStr", ds.Tables[0].Rows[0]["nonce_str"].ToString() },
                            { "package", "prepay_id=" + ds.Tables[0].Rows[0]["prepay_id"].ToString() },
                            { "signType", "MD5" },
                            { "timeStamp", ut.GetTimeStamp() },
                        };
                        res.Add("paySign", ut.GetSignString(res));
                        List <Order> orderArray = new List <Order>();
                        Order        order      = new Order();
                        order.timeStamp       = res["timeStamp"];
                        order.nonceStr        = res["nonceStr"];
                        order.package         = res["package"];
                        order.paySign         = res["paySign"];
                        order.wx_out_trade_no = wx_out_trade_no;
                        rm.RetCode            = 0;
                        orderArray.Add(order);
                        rm.data = orderArray;
                    }
                    else
                    {
                        rm.RetCode  = -2;
                        rm.ErrorMsg = ut.getErrMessage(rm.RetCode);
                    }
                }
            }
            else
            {
                rm.RetCode  = -3;
                rm.ErrorMsg = ut.getErrMessage(rm.RetCode);
            }
            return(rm);
        }