Пример #1
0
    protected string GetSignalTicket(string timeStamp, string appId, string APPSECRET)
    {
        string      acetoken = GetAccessToken(appId, APPSECRET);
        string      signal   = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + acetoken + "&type=jsapi";
        ReturnValue retValue = StreamReaderUtils.StreamReader(signal, Encoding.UTF8);

        string ticket = StringUtils.GetJsonValue(retValue.Message, "ticket").ToString();

        string url = "jsapi_ticket=" + ticket + "&noncestr=Wm3WZYTPz0wzccnW&timestamp=" + timeStamp + "&url=" + Request.Url.AbsoluteUri.ToString();

        return(SHA1_Hash(url));
    }
Пример #2
0
    public ReturnValue GetUserInfo(ref string strAccess_Token, string APPID, string APPSECRET)
    {
        string       timeStamp           = "";
        const string TENPAY              = "1";
        const string mchid               = "1242234302";//商户号
        const string OAUTH2              = "https://open.weixin.qq.com/connect/oauth2/authorize";
        const string OAUTH2_ACCESS_TOKEN = "https://api.weixin.qq.com/sns/oauth2/access_token";
        string       strWeixin_OpenID    = "";

        timeStamp = TenpayUtil.getTimestamp();
        string strCode = Request["code"] == null ? "" : Request["code"];

        if (string.IsNullOrEmpty(strCode))
        {
            //参数需要自己处理
            string _OAuth_Url = Interface_WxPay.OAuth2_GetUrl_Pay(Request.Url.ToString(), APPID);
            Response.Redirect(_OAuth_Url);
            return(null);
        }
        else
        {
            ReturnValue retValue = Interface_WxPay.OAuth2_Access_Token(strCode, APPID, APPSECRET);
            if (retValue.HasError)
            {
                // WriteFile(Server.MapPath("") + "\\Log.txt", "ewrwrwrwrwrwrer");

                Response.Write("获取code失败:" + retValue.Message);
                return(null);
            }

            // WriteFile(Server.MapPath("") + "\\Log.txt", "11111111111111111");
            strWeixin_OpenID = retValue.GetStringValue("Weixin_OpenID");
            string strWeixin_Token = retValue.GetStringValue("Weixin_Token");
            strAccess_Token = strWeixin_Token;
            string refresh_token = retValue.GetStringValue("refresh_token");
            //WriteFile(Server.MapPath("") + "\\Log.txt", "2222222222222222");
            //  Response.Write(strWeixin_OpenID);
            if (string.IsNullOrEmpty(strWeixin_OpenID))
            {
                Response.Write("openid出错");
                return(null);
            }

            string userinfotoken = "https://api.weixin.qq.com/sns/userinfo?access_token=" + strWeixin_Token + "&openid=" + strWeixin_OpenID + "&lang=zh_CN";

            retValue = StreamReaderUtils.StreamReader(userinfotoken, Encoding.UTF8);
            return(retValue);
        }
    }
Пример #3
0
    public string LoadPayID(string openid, string Bill_No, decimal Charge_Amt, string Body)
    {
        string APPID = WebConfigurationManager.AppSettings["CorpId"];
        // string TENPAY = "1";
        string PARTNER     = WebConfigurationManager.AppSettings["PARTNER"]; // "1259901501";//商户号
        string APPSECRET   = WebConfigurationManager.AppSettings["WeixinAppSecret"];
        string PARTNER_KEY = WebConfigurationManager.AppSettings["JSPIKey"]; // "6f498ef1c21be21531b39dd1c668c26f";//APPSECRET
        string strPAYURL   = "http://yanwo.x76.com.cn/PayNotifyUrl.aspx";    // 不允许传递参数

        HttpContext Context = System.Web.HttpContext.Current;

        if (openid.Length == 0)
        {
            return(string.Empty);
        }

        //设置package订单参数
        SortedDictionary <string, string> dic = new SortedDictionary <string, string>();

        string strIP = Context.Request.UserHostAddress;// "127.0.0.1";//

        string total_fee    = (Charge_Amt * 100).ToString("f0");
        string wx_timeStamp = "";
        string wx_nonceStr  = getNoncestr();

        dic.Add("appid", APPID);
        dic.Add("mch_id", PARTNER);     //财付通帐号商家
        dic.Add("device_info", "1000"); //可为空
        dic.Add("nonce_str", wx_nonceStr);
        dic.Add("trade_type", "JSAPI");
        dic.Add("attach", "att1");
        dic.Add("openid", openid);
        dic.Add("out_trade_no", Bill_No);           //商家订单号
        dic.Add("total_fee", total_fee);            //商品金额,以分为单位(money * 100).ToString()
        dic.Add("notify_url", strPAYURL.ToLower()); //接收财付通通知的URL
        dic.Add("body", Body);                      //商品描述
        dic.Add("spbill_create_ip", strIP);         //用户的公网ip,不是商户服务器IP

        string get_sign = BuildRequest(dic, PARTNER_KEY);

        string url       = "https://api.mch.weixin.qq.com/pay/unifiedorder";
        string _req_data = "<xml>";

        _req_data += "<appid>" + APPID + "</appid>";
        _req_data += "<mch_id><![CDATA[" + PARTNER + "]]></mch_id> ";
        _req_data += "<device_info><![CDATA[1000]]></device_info> ";
        _req_data += "<nonce_str><![CDATA[" + wx_nonceStr + "]]></nonce_str> ";
        _req_data += "<trade_type><![CDATA[JSAPI]]></trade_type> ";
        _req_data += "<attach><![CDATA[att1]]></attach>";
        _req_data += "<openid><![CDATA[" + openid + "]]></openid> ";
        _req_data += "<out_trade_no><![CDATA[" + Bill_No + "]]></out_trade_no> ";
        _req_data += "<total_fee><![CDATA[" + total_fee + "]]></total_fee> ";
        _req_data += "<notify_url><![CDATA[" + strPAYURL.ToLower() + "]]></notify_url> ";
        _req_data += "<body><![CDATA[" + Body + "]]></body> ";
        _req_data += "<spbill_create_ip><![CDATA[" + strIP + "]]></spbill_create_ip> ";
        _req_data += "<sign><![CDATA[" + get_sign + "]]></sign> ";
        _req_data += "</xml>";

        //通知支付接口,拿到prepay_id
        ReturnValue retValue = StreamReaderUtils.StreamReader(url, Encoding.UTF8.GetBytes(_req_data), System.Text.Encoding.UTF8, true);

        //return retValue.Message;
        ////设置支付参数
        XmlDocument xmldoc = new XmlDocument();

        xmldoc.LoadXml(retValue.Message);

        XmlNode Event = xmldoc.SelectSingleNode("/xml/prepay_id");

        string return_json = "";

        if (Event != null)
        {
            string _prepay_id = Event.InnerText;

            SortedDictionary <string, string> pay_dic = new SortedDictionary <string, string>();

            wx_timeStamp = getTimestamp();
            wx_nonceStr  = getNoncestr();

            string _package = "prepay_id=" + _prepay_id;

            pay_dic.Add("appId", APPID);
            pay_dic.Add("timeStamp", wx_timeStamp);
            pay_dic.Add("nonceStr", wx_nonceStr);
            pay_dic.Add("package", _package);
            pay_dic.Add("signType", "MD5");

            string get_PaySign = BuildRequest(pay_dic, PARTNER_KEY);

            return_json = JsonUtils.SerializeToJson(new
            {
                appId     = APPID,
                timeStamp = wx_timeStamp,
                nonceStr  = wx_nonceStr,
                package   = _package,
                signType  = "MD5",
                paySign   = get_PaySign
            });
        }

        return(return_json);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["type"] == "GetTrace")
        {
            MQueryParameter para = new MQueryParameter();
            para.TypeCom = "申通快递";
            para.OrderId = "3323401314893";
            MResultMsg msg = ExpressageHelper.GetExpressageMessage(para);
            Response.Write(msg.JsonMessage);
            Response.End();
        }


        if (!IsPostBack)
        {
            ((HtmlContainerControl)Master.FindControl("HTitle")).InnerText = IsCN ? "订单查询" : "Order Query";
        }

        string acetoken = GetAccessToken(Session["APPID"].ToString(), Session["APPSECRET"].ToString());

        timeStamp = TenpayUtil.getTimestamp();
        string      signal   = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + acetoken + "&type=jsapi";
        ReturnValue retValue = StreamReaderUtils.StreamReader(signal, Encoding.UTF8);

        string ticket = StringUtils.GetJsonValue(retValue.Message, "ticket").ToString();

        string url = "jsapi_ticket=" + ticket + "&noncestr=Wm3WZYTPz0wzccnW&timestamp=" + timeStamp + "&url=" + Request.Url.AbsoluteUri.ToString();

        signalticket = SHA1_Hash(url);

        try
        {
            servCommfac = new ServiceCommon(base.factoryConnectionString);
            if (!IsPostBack)
            {
                if (Request["returnValue"] == null)
                {
                    Session["returnValue"] = null;
                }
            }



            ccWhere.Clear();
            ccWhere = querycontrol.GetCondtion();
            //默认显示的是在厂的订单,不要显示已经出厂的订单

            servCommfac.strOrderString = querycontrol.OrderString == "" ? " regtime desc " : querycontrol.OrderString;

            hddpnumbers = yeyRequest.Params("hpnumbers");
            int iCount = 5;
            if (!string.IsNullOrEmpty(hddpnumbers))
            {
                iCount = Convert.ToInt32(hddpnumbers);
            }

            iPageIndex = string.IsNullOrEmpty(Request["sPageID"]) ? 1 : Convert.ToInt32(Request["sPageID"]);
            int iPageCount = string.IsNullOrEmpty(Request["sPageNum"]) ? 0 : Convert.ToInt32(Request["sPageNum"]);
            if (Request["submitflg"] != null && Request["submitflg"] == "1")
            {
                iPageIndex = 1;
                this.pagecutID.iPageIndex = 1;
                iPageCount = 0;
            }

            string sortList = Request["sortList"];


            if (Utils.IsNoSP == false)
            {
                ilist = servCommfac.GetList <ORDERS>(ORDERS.STRTABLENAME, "Order_ID,seller,sellerid,hospital,ModelNo,hospitalid,doctor,serial,patient,orderclass,indate,process," +
                                                     "case when Hurry = 'Y' then 0 else '1' end as Hurry,case when TryPut = 'Y' then 0 else '1' end as TryPut,case when Slow = 'Y' then 0 else '1' end as Slow,preoutDate,case when preoutDate > GETDATE()then 1 else 0 end as expire ", ORDERS.STRKEYNAME, iCount, iPageIndex, iPageCount, ccWhere);
                this.pagecutID.iPageNum = servCommfac.PageCount;
            }
            else
            {
                int       rowCount  = servCommfac.GetCount("ORDERS", ccWhere);
                string    filedshow = " row_number()over(order by Order_ID,serial) as rowIndex ,Order_ID, seller, sellerid, hospital, ModelNo, hospitalid, doctor, serial, patient, orderclass, indate, process,case when Hurry = 'Y' then 0 else '1' end as Hurry,case when TryPut = 'Y' then 0 else '1' end as TryPut,case when Slow = 'Y' then 0 else '1' end as Slow,preoutDate,case when preoutDate > GETDATE()then 1 else 0 end as expire";
                DataTable dt        = servCommfac.ExecuteSqlDatatable("select * from (select " + filedshow + " from ORDERS  where 1=1 and " + ccWhere.sbComponent + ") t where rowIndex>=" + ((iPageIndex - 1) * iCount + 1).ToString() + " and rowIndex <=" + iPageIndex * iCount);
                ilist = Utils.ConvertTo <ORDERS>(dt);
                servCommfac.RowCount    = rowCount;
                this.pagecutID.iPageNum = (rowCount - 1) / iCount + 1;
            }

            if (ilist.Count == 0)
            {
                servCommfac.PageCount = 0;
            }

            iPageAllCount = this.pagecutID.iPageNum;
        }
        catch (Exception ex) {
        }
    }