예제 #1
0
        //获取package带参数的签名包
        public string getRequestURL()
        {
            this.createSign();
            StringBuilder sb    = new StringBuilder();
            ArrayList     akeys = new ArrayList(parameters.Keys);

            akeys.Sort();
            foreach (string k in akeys)
            {
                string v = (string)parameters[k];
                if (null != v && "key".CompareTo(k) != 0)
                {
                    sb.Append(k + "=" + TenpayUtil.UrlEncode(v, getCharset()) + "&");
                }
            }

            //去掉最后一个&
            if (sb.Length > 0)
            {
                sb.Remove(sb.Length - 1, 1);
            }


            return(sb.ToString());
        }
예제 #2
0
        public string GetPrepayId(string operater, string trade_type, string openid, string orderSn, decimal orderAmount, string goods_tag, string ip, string body, DateTime?time_expire = null)
        {
            CustomJsonResult result = new CustomJsonResult();


            TenpayUtil tenpayUtil = new TenpayUtil(wxConfig);

            UnifiedOrder unifiedOrder = new UnifiedOrder();

            unifiedOrder.openid           = openid;
            unifiedOrder.out_trade_no     = orderSn;                            //商户订单号
            unifiedOrder.spbill_create_ip = ip;                                 //终端IP
            unifiedOrder.total_fee        = Convert.ToInt32(orderAmount * 100); //标价金额
            unifiedOrder.body             = body;                               //商品描述
            unifiedOrder.trade_type       = trade_type;
            if (time_expire != null)
            {
                unifiedOrder.time_expire = time_expire.Value.ToString("yyyyMMddHHmmss");
            }

            if (!string.IsNullOrEmpty(goods_tag))
            {
                unifiedOrder.goods_tag = goods_tag;
            }

            string prepayId = tenpayUtil.GetPrepayId(unifiedOrder);

            //using (TransactionScope ts = new TransactionScope())
            //{

            //    result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "操作成功");
            //}

            return(prepayId);
        }
예제 #3
0
        public UnifiedOrderResult UnifiedOrderByJsApi(WxAppInfoConfig config, string openId, string orderSn, decimal orderAmount, string goods_tag, string ip, string body, DateTime?time_expire = null)
        {
            var ret = new UnifiedOrderResult();

            TenpayUtil tenpayUtil = new TenpayUtil(config);

            UnifiedOrder unifiedOrder = new UnifiedOrder();

            unifiedOrder.openid           = openId;
            unifiedOrder.out_trade_no     = orderSn;                            //商户订单号
            unifiedOrder.spbill_create_ip = "192.168.1.1";                      //终端IP
            unifiedOrder.total_fee        = Convert.ToInt32(orderAmount * 100); //标价金额
            unifiedOrder.body             = body;                               //商品描述
            unifiedOrder.trade_type       = "JSAPI";
            if (time_expire != null)
            {
                unifiedOrder.time_expire = time_expire.Value.ToString("yyyyMMddHHmmss");
            }

            if (!string.IsNullOrEmpty(goods_tag))
            {
                unifiedOrder.goods_tag = goods_tag;
            }

            ret = tenpayUtil.UnifiedOrder(unifiedOrder);

            return(ret);
        }
예제 #4
0
        /// <summary>
        /// 微信转账
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="config">配置</param>
        /// <returns>结果</returns>
        public static TransfersResult Transfers(TransfersRequest request, Config config)
        {
            TransfersResult       result = new TransfersResult();
            TransfersQueryRequest transfersQueryRequest = new TransfersQueryRequest
            {
                PartnerTradeNo = request.PartnerTradeNo
            };
            TransfersQueryResult transfersQueryResult = TransfersQuery(transfersQueryRequest, config);

            if (transfersQueryResult.Status == TransfersStatus.Success)
            {
                result.IsSuccess = TransfersStatus.Success;
                return(result);
            }
            if (transfersQueryResult.Status == TransfersStatus.Processing)
            {
                result.IsSuccess = TransfersStatus.Processing;
                return(result);
            }

            var requestStr = TenpayUtil.GetTransfersRequestXml(request, config);
            var response   = HttpHelp.PostXmlToUrl(Config.TransfersUrl, requestStr, config.GetTransfersCertPath(), config.GetPid());

            result = TenpayUtil.ConvertToTransfersResult(response);
            return(result);
        }
예제 #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            TenpayUtil      tenpayUtil      = new TenpayUtil();
            ResponseHandler responseHandler = new ResponseHandler(this.Context);

            responseHandler.setKey(tenpayUtil.key);
            if (responseHandler.isTenpaySign())
            {
                responseHandler.getParameter("notify_id");
                string upper = responseHandler.getParameter("out_trade_no").ToUpper();
                responseHandler.getParameter("transaction_id");
                responseHandler.getParameter("total_fee");
                responseHandler.getParameter("discount");
                string parameter = responseHandler.getParameter("trade_state");
                responseHandler.getParameter("trade_mode");
                if ("0".Equals(parameter))
                {
                    this.Response.Redirect(new BasePage().linkurl("payment", (object)("?action=succeed&order_no=" + upper)));
                }
                else
                {
                    this.Response.Redirect(new BasePage().linkurl("payment", (object)"?action=error"));
                }
            }
            else
            {
                this.Response.Redirect(new BasePage().linkurl("payment", (object)"?action=error"));
            }
        }
예제 #6
0
        /// <summary>
        /// 获取openId
        /// </summary>
        /// <param name="request">请求参数</param>
        /// <param name="config">配置</param>
        /// <returns>结果</returns>
        public static string GetOpenidFromCode(OpenidFromCodeRequest request, Config config)
        {
            var url  = TenpayUtil.GetOpenidFromCodeUrl(request, config);
            var data = HttpHelp.GetUrl(url);

            return(data);
        }
예제 #7
0
    public string Get_signature()
    {
        //加密/校验流程:
        //string noncestr = "noncestr=Wm3WZYTPz0wzccnW";
        //string timestamp = "timestamp=1414587457";
        //string jsapi_ticket = "jsapi_ticket=sM4AOVdWfPE4DxkXGEs8VMCPGGVi4C3VM0P37wVUCFvkVAy_90u5h9nbSlYy3-Sl-HhTdfl2fzFy1AOcHKP7qg";
        string noncestr     = "noncestr=" + TenpayUtil.getNoncestr();
        string timestamp    = "timestamp=" + TenpayUtil.getTimestamp();
        string jsapi_ticket = "";

        if (HttpRuntime.Cache["jsapi_ticket"] == null)
        {
            //重新获取jsapi_ticket
        }
        else
        {
            jsapi_ticket = "jsapi_ticket=" + HttpRuntime.Cache["jsapi_ticket"].ToString();
        }
        //string url = "url=http://mp.weixin.qq.com?params=value";
        string url = "url=" + Request.Url.ToString();

        //1. 对所有待签名参数按照字段名的ASCII 码从小到大排序(字典序)后,
        //使用URL键值对的格式(即key1=value1&key2=value2…)拼接成字符串string1
        string[] ArrTmp = { noncestr, timestamp, jsapi_ticket, url };
        Array.Sort(ArrTmp);//字典排序
        //2.将三个参数字符串拼接成一个字符串进行sha1加密
        string tmpStr = string.Join("&", ArrTmp);

        tmpStr = FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "SHA1");
        tmpStr = tmpStr.ToLower();
        return(tmpStr);
    }
예제 #8
0
파일: Notify.cs 프로젝트: vuongthai91/Fund
        /// <summary>
        /// 接收推送消息
        /// </summary>
        /// <param name="xml">请求消息</param>
        /// <param name="configData">configData</param>
        /// <returns>处理结果</returns>
        public static PushResult ReceivePushMessage(string xml, ConfigData configData)
        {
            PushRequest pushRequest = new PushRequest
            {
                Xml                   = xml,
                EncodingAESKey        = configData.EncodingAESKey,
                ComponentVerifyTicket = configData.component_verify_ticket_key,
                ValidityTime          = DateTime.Now.AddDays(1)
            };
            XElement   doc            = XElement.Parse(pushRequest.Xml);
            var        encry          = doc.Element("Encrypt").GetString();
            string     encodingAESKey = pushRequest.EncodingAESKey;
            string     appid          = string.Empty;
            var        xmlContent     = Cryptography.AES_decrypt(encry, encodingAESKey, ref appid);
            PushResult pushResult     = TenpayUtil.ConvertToPushRequest(xmlContent);

            if (pushResult.InfoType == "component_verify_ticket")
            {
                // 写入缓存
                //Redis.SetRedis(pushRequest.ComponentVerifyTicket, pushResult.ComponentVerifyTicket, pushRequest.ValidityTime);
                pushResult.IsSucceed = !string.IsNullOrEmpty(pushRequest.ComponentVerifyTicket);
            }
            else
            {
                pushResult.IsSucceed = false;
                pushResult.Message   = $"暂不处理类型{pushResult.InfoType}";
            }
            return(pushResult);
        }
예제 #9
0
        /// <summary>
        /// 第一种扫码生成二维码----生成二维码
        /// </summary>
        /// <returns></returns>
        public string GetCode()
        {
            //   weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX&product_id=XXXXXX&time_stamp=XXXXXX&nonce_str=XXXXX



            string appid = tenpay.WeChartConfigItem.appid;

            string mch_id = tenpay.WeChartConfigItem.mch_id;

            string product_id = "888654444";

            string time_stamp = TenpayUtil.getTimestamp();

            string nonce_str = TenpayUtil.getNoncestr();


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

            dic.Add("appid", appid);
            dic.Add("mch_id", mch_id);
            dic.Add("product_id", product_id);
            dic.Add("time_stamp", time_stamp);
            dic.Add("nonce_str", nonce_str);
            string sign = TenpayUtil.getsign(dic, "43804496F28A4F0FBF1195AA0F1Abcde");

            return("weixin://wxpay/bizpayurl?sign=" + sign + "&appid=" + appid + "&mch_id=" + mch_id + "&product_id=" + product_id + "&time_stamp=" + time_stamp + "&nonce_str=" + nonce_str);
        }
예제 #10
0
        /** 获取带参数的请求URL  @return String */
        public virtual string getRequestURL()
        {
            this.createSign();

            StringBuilder sb    = new StringBuilder();
            ArrayList     akeys = new ArrayList(parameters.Keys);

            akeys.Sort();
            foreach (string k in akeys)
            {
                string v = (string)parameters[k];
                if (null != v && "key".CompareTo(k) != 0 && "spbill_create_ip".CompareTo(k) != 0)
                {
                    sb.Append(k + "=" + TenpayUtil.UrlEncode(v, getCharset()) + "&");
                }
                else if ("spbill_create_ip".CompareTo(k) == 0)
                {
                    sb.Append(k + "=" + v.Replace(".", "%2E") + "&");
                }
            }

            //去掉最后一个&
            if (sb.Length > 0)
            {
                sb.Remove(sb.Length - 1, 1);
            }

            return(this.getGateUrl() + "?" + sb.ToString());
        }
예제 #11
0
        /// <summary>
        /// 订单查询接口
        /// </summary>
        /// <param name="request">请求信息</param>
        /// <param name="config">配置</param>
        /// <returns>结果</returns>
        public static OrderQueryResult OrderQuery(OrderQueryRequest request, Config config)
        {
            var requestStr = TenpayUtil.GetOrderqueryRequestXml(request, config);
            var response   = HttpHelp.PostXmlToUrl(Config.OrderQueryUrl, requestStr);
            var result     = TenpayUtil.ConvertToOrderqueryResult(response);

            return(result);
        }
예제 #12
0
        public string OrderQuery(WxAppInfoConfig config, string orderSn)
        {
            CustomJsonResult result     = new CustomJsonResult();
            TenpayUtil       tenpayUtil = new TenpayUtil(config);
            string           xml        = tenpayUtil.OrderQuery(orderSn);

            return(xml);
        }
예제 #13
0
        /// <summary>
        /// 微信零钱转账查询
        /// </summary>
        /// <param name="request">查询信息</param>
        /// <param name="config">配置</param>
        /// <returns>结果</returns>
        public static TransfersQueryResult TransfersQuery(TransfersQueryRequest request, Config config)
        {
            var requestStr = TenpayUtil.GetTransfersQueryRequestXml(request, config);
            var response   = HttpHelp.PostXmlToUrl(Config.TransferinfoUrl, requestStr, config.GetTransfersQueryCertPath(), config.GetPid());
            var result     = TenpayUtil.ConvertToTransfersQueryResult(response);

            return(result);
        }
예제 #14
0
        /// <summary>
        /// 退款查询
        /// </summary>
        /// <param name="request">查询信息</param>
        /// <param name="config">配置</param>
        /// <returns>结果</returns>
        public static RefundQueryResult RefundPayQuery(RefundQueryRequest request, Config config)
        {
            var requestStr = TenpayUtil.GetRefundQueryRequestXml(request, config);
            var response   = HttpHelp.PostXmlToUrl(Config.RefundQueryUrl, requestStr);
            var result     = TenpayUtil.ConvertToRefundQueryResult(response);

            return(result);
        }
예제 #15
0
파일: mch.cs 프로젝트: xiaopohou/YuChang
            public static string unifiedorder(string appid, string mch_id, string openid, string key, string body, string notify_url,
                                              string out_trade_no, int total_fee)
            {
                //string appId = this.accessToken.AppId;
                //string parameterValue = this.partnerId;
                var            spbill_create_ip = "127.0.0.1";
                string         noncestr         = TenpayUtil.getNoncestr();
                string         parameterValue2  = "JSAPI";
                RequestHandler requestHandler   = new RequestHandler(Encoding.UTF8);

                requestHandler.setKey(key);
                requestHandler.setParameter("appid", appid);
                requestHandler.setParameter("body", body);
                requestHandler.setParameter("mch_id", mch_id);
                requestHandler.setParameter("nonce_str", noncestr);
                requestHandler.setParameter("notify_url", notify_url);
                requestHandler.setParameter("openid", openid);
                requestHandler.setParameter("out_trade_no", out_trade_no);
                requestHandler.setParameter("spbill_create_ip", spbill_create_ip);
                requestHandler.setParameter("total_fee", total_fee.ToString());
                requestHandler.setParameter("trade_type", parameterValue2);
                string text    = requestHandler.createMd5Sign();
                string data    = requestHandler.parseXML();
                string address = "https://api.mch.weixin.qq.com/pay/unifiedorder";
                string xml     = new WebClient
                {
                    Encoding = Encoding.UTF8
                }.UploadString(address, "post", data);
                XmlDocument xmlDocument = new XmlDocument();

                xmlDocument.LoadXml(xml);
                XmlElement[] source    = xmlDocument.FirstChild.ChildNodes.Cast <XmlElement>().ToArray <XmlElement>();
                string       innerText = source.Single((XmlElement o) => o.Name == "return_code").InnerText;

                if (!(innerText != "SUCCESS"))
                {
                    return(source.Single((XmlElement o) => o.Name == "prepay_id").InnerText);
                }
                string text2 = (
                    from o in source
                    where o.Name == "err_code"
                    select o.InnerText).SingleOrDefault <string>();
                string text3 = (
                    from o in source
                    where o.Name == "err_code_des"
                    select o.InnerText).SingleOrDefault <string>();

                if (text2 != null && text3 != null)
                {
                    throw Error.WeiXinError(text2, text3);
                }
                string msg = (
                    from o in source
                    where o.Name == "return_msg"
                    select o.InnerText).SingleOrDefault <string>() ?? "ERROR";

                throw Error.WeiXinError(innerText, msg);
            }
예제 #16
0
        /// <summary>
        /// 创建支付信息(网页公众号)
        /// </summary>
        /// <param name="request">request</param>
        /// <param name="config">配置</param>
        /// <returns>结果</returns>
        public static WapUnifiedOrderResult CreateDirectWapPayByUser(WapUnifiedOrderRequest request, Config config)
        {
            // 统一下单
            var requestStr         = TenpayUtil.GetUnifiedWapOrderXml(request, config);
            var response           = HttpHelp.PostXmlToUrl(Config.UnifiedPayUrl, requestStr);
            var unifiedOrderResult = TenpayUtil.ConvertToWapUnifiedOrderResult(response);
            // 调起支付
            var parameters = TenpayUtil.GetWapPaySign(unifiedOrderResult, config);
            var result     = TenpayUtil.CreatePayParameters(parameters, unifiedOrderResult);

            return(result);
        }
예제 #17
0
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="wechatUserRequest">wechatUserRequest</param>
        /// <param name="config">config</param>
        /// <returns>关注的openid</returns>
        public static WechatUser GetWechatUser(WechatUserRequest wechatUserRequest, Config config)
        {
            string     url        = TenpayUtil.GetUserUrl(wechatUserRequest, config, false);
            var        strSendRes = HttpHelp.GetUrl(url);
            WechatUser wechatUser = JsonConvert.DeserializeObject <WechatUser>(strSendRes);

            if (wechatUser.Errcode == "40001")
            {
                string url1        = TenpayUtil.GetUserUrl(wechatUserRequest, config, true);
                var    strSendRes1 = HttpHelp.GetUrl(url1);
                wechatUser = JsonConvert.DeserializeObject <WechatUser>(strSendRes1);
            }
            return(wechatUser);
        }
예제 #18
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);
        }
    }
예제 #19
0
파일: Notify.cs 프로젝트: vuongthai91/Fund
        /// <summary>
        /// 支付通知结果解析
        /// </summary>
        /// <param name="xml">xml</param>
        /// <param name="config">config</param>
        /// <returns>支付通知结果</returns>
        public static PayNotifyResult PayNotify(string xml, Config config)
        {
            var result = TenpayUtil.ConvertToPayNotifyRresult(xml);

            if (result.PayNotifyRresult.IsSuccess)
            {
                if (Signature.VerifySign(result.SignParanmeters, result.SignParanmeters["sign"], config.GetKey()))
                {
                    return(result.PayNotifyRresult);
                }
                result.PayNotifyRresult.IsSuccess = false;
                result.PayNotifyRresult.Message   = "签名错误";
                return(result.PayNotifyRresult);
            }
            return(result.PayNotifyRresult);
        }
예제 #20
0
        public string RequestPay(string ordernum, string return_url, double?PayMoney, string ProductName, string Remark)
        {
            //创建PayRequestHandler实例
            PayRequestHandler reqHandler = new PayRequestHandler(context);

            Model.SitePayAPI m_entity = Model.SitePayAPI.GetModel(t => t.ApiType == "财付通");
            //商户号
            string bargainor_id = m_entity.AppIdentity;

            //设置密钥
            reqHandler.setKey(m_entity.AppKey);

            //初始化
            reqHandler.init();

            //当前时间 yyyyMMdd
            string date = DateTime.Now.ToString("yyyyMMdd");

            //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
            string strReq = DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);


            //财付通订单号,10位商户号+8位日期+10位序列号,需保证全局唯一
            string transaction_id = bargainor_id + date + strReq;


            //-----------------------------
            //设置支付参数
            //-----------------------------
            reqHandler.setParameter("bargainor_id", bargainor_id);                    //商户号
            reqHandler.setParameter("sp_billno", ordernum);                           //商家订单号
            reqHandler.setParameter("transaction_id", transaction_id);                //财付通交易单号
            reqHandler.setParameter("return_url", return_url);                        //支付通知url
            reqHandler.setParameter("desc", ProductName);                             //商品名称
            reqHandler.setParameter("attach", Remark == null?"":Remark);              //会员ID
            reqHandler.setParameter("total_fee", ((int)(PayMoney * 100)).ToString()); //商品金额,以分为单位


            //用户ip,测试环境时不要加这个ip参数,正式环境再加此参数
            reqHandler.setParameter("spbill_create_ip", DealMvc.Common.Globals.GetUserIP());

            //获取请求带参数的url
            string requestUrl = reqHandler.getRequestURL();

            return(requestUrl);
            //FinalMessage("正在进入财付通网站...", requestUrl, 0, 4);
        }
예제 #21
0
        protected void Page_Load(object sender, EventArgs e)
        {
            TenpayUtil xmlConfig = new TenpayUtil();
            //创建ResponseHandler实例
            ResponseHandler resHandler = new ResponseHandler(Context);

            resHandler.setKey(xmlConfig.key);

            //判断签名
            if (resHandler.isTenpaySign())
            {
                //通知id
                string notify_id = resHandler.getParameter("notify_id");
                //商户订单号
                string out_trade_no = resHandler.getParameter("out_trade_no").ToUpper();
                //财付通订单号
                string transaction_id = resHandler.getParameter("transaction_id");
                //金额,以分为单位
                string total_fee = resHandler.getParameter("total_fee");
                //如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee
                string discount = resHandler.getParameter("discount");
                //支付结果
                string trade_state = resHandler.getParameter("trade_state");
                //交易模式,1即时到账,2中介担保
                string trade_mode = resHandler.getParameter("trade_mode");

                if ("0".Equals(trade_state))
                {
                    //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                    Response.Redirect(new Web.UI.BasePage().linkurl("payment", "?action=succeed&order_no=" + out_trade_no));
                    return;
                }
                else
                {
                    //失败状态
                    Response.Redirect(new Web.UI.BasePage().linkurl("payment", "?action=error"));
                    return;
                }
            }
            else
            {
                //认证签名失败
                Response.Redirect(new Web.UI.BasePage().linkurl("payment", "?action=error"));
            }
        }
예제 #22
0
파일: Notify.cs 프로젝트: vuongthai91/Fund
        /// <summary>
        /// 退款通知结果解析
        /// </summary>
        /// <param name="xml">xml</param>
        /// <param name="config">config</param>
        /// <returns>退款结果</returns>
        public static RefundPayNotifyResult RefundPayNotify(string xml, Config config)
        {
            RefundPayNotifyResult refundPayNotifyResult = new RefundPayNotifyResult();
            var reqInfo = TenpayUtil.GetRefunPayNotifyReqInfo(xml);

            if (reqInfo.Key != null)
            {
                var stringA    = Security.Encrypt32(config.GetKey()).ToLower();
                var reqInfoXml = Security.AesDecrypt(reqInfo.Key, stringA);
                refundPayNotifyResult = TenpayUtil.ConvertToRefundPayNotifyResult(reqInfoXml);
            }
            else
            {
                refundPayNotifyResult.IsSuccess = "CHANGE";
                refundPayNotifyResult.Message   = reqInfo.Value;
            }
            return(refundPayNotifyResult);
        }
예제 #23
0
        /// <summary>
        /// 财付通生成URL
        /// </summary>
        /// <param name="orderNo"></param>
        /// <param name="subject_in"></param>
        /// <param name="price_in"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public string GetPayUrlByCFT(string orderNo, string subject_in, decimal price_in, HttpContext context)
        {
            string url = "";
            //商户号
            string bargainor_id = TenpayParameters.Bargainor_ID;
            //密钥
            string key1 = TenpayParameters.Key;

            //当前时间 yyyyMMdd
            string date = DateTime.Now.ToString("yyyyMMdd");
            ////生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
            string strReq = "" + DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);

            ////商户订单号,不超过32位,财付通只做记录,不保证唯一性
            //string sp_billno = strReq;

            // 财付通交易单号,规则为:10位商户号+8位时间(YYYYmmdd)+10位流水号 ,商户根据自己情况调整,只要保证唯一及符合规则就行
            string transaction_id = bargainor_id + date + strReq;


            //创建PayRequestHandler实例
            PayRequestHandler reqHandler = new PayRequestHandler(context);

            //初始化
            reqHandler.init();
            //设置密钥
            reqHandler.setKey(key1);
            //-----------------------------
            //设置支付参数
            //-----------------------------
            reqHandler.setParameter("bargainor_id", bargainor_id);                                                        //商户号
            reqHandler.setParameter("sp_billno", orderNo);                                                                //商家订单号
            reqHandler.setParameter("transaction_id", transaction_id);                                                    //财付通交易单号
            reqHandler.setParameter("return_url", TenpayParameters.DomainPath + "/TicketsCenter/tenpay/Return_url.aspx"); //支付通知url
            reqHandler.setParameter("desc", subject_in);                                                                  //商品名称
            reqHandler.setParameter("total_fee", price_in.ToString());                                                    //商品金额,以分为单
            reqHandler.setParameter("cs", TenpayParameters.Input_Charset);
            //用户的公网ip,测试时填写127.0.0.1,只能支持10分以下交易
            reqHandler.setParameter("spbill_create_ip", HttpContext.Current.Request.UserHostAddress);
            //获取请求带参数的url
            url = reqHandler.getRequestURL();

            return(url);
        }
예제 #24
0
파일: index.aspx.cs 프로젝트: uvbs/tumumi
    protected void Page_Load(object sender, EventArgs e)
    {
        //创建工具对象,读取配置
        TenpayUtil util = new TenpayUtil();

        if (!IsPostBack)
        {
            //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
            string strReq = DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);

            //当前时间 yyyyMMdd
            string date = DateTime.Now.ToString("yyyyMMdd");

            //商户订单号,不超过32位,财付通只做记录,不保证唯一性
            string sp_billno = date + strReq;
            lbl_Name.Text = TenpayUtil.bargainor_id;
            order_no.Text = sp_billno;
        }
    }
예제 #25
0
        /// <summary>
        /// 发送模版消息
        /// </summary>
        /// <param name="templateMsg">发送消息内容</param>
        /// <param name="config">配置</param>
        /// <returns>结果</returns>
        public static Result SendTemplateMessage <T>(TemplateMsg <T> templateMsg, Config config)
        {
            Result            res        = new Result();
            var               configData = config;
            string            url        = TenpayUtil.GetTemplateUrl(configData, false);
            var               strSendRes = HttpHelp.PostXmlToUrl(url, JsonConvert.SerializeObject(templateMsg));
            TemplateMsgResult sendRes    = JsonConvert.DeserializeObject <TemplateMsgResult>(strSendRes);

            res.IsSucceed = sendRes.ErrorMsg.Trim().ToLower() == "ok";
            res.Message   = sendRes.ErrorMsg;
            if (sendRes.ErrorCode == 40001)
            {
                string            url1        = TenpayUtil.GetTemplateUrl(configData, true);
                var               strSendRes1 = HttpHelp.PostXmlToUrl(url1, JsonConvert.SerializeObject(templateMsg));
                TemplateMsgResult sendRes1    = JsonConvert.DeserializeObject <TemplateMsgResult>(strSendRes1);
                res.IsSucceed = sendRes1.ErrorMsg.Trim().ToLower() == "ok";
                res.Message   = sendRes1.ErrorMsg;
            }
            return(res);
        }
예제 #26
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string sp_billno = Request["order_no"];
            //当前时间 yyyyMMdd
            string date = DateTime.Now.ToString("yyyyMMdd");

            if (null == sp_billno)
            {
                //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
                sp_billno = DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);
            }
            else
            {
                sp_billno = Request["order_no"].ToString();
            }

            sp_billno = TenpayUtil.partner + sp_billno;


            RequestHandler outParams = new RequestHandler(Context);

            outParams.init();
            string productid = sp_billno;
            string timeStamp = TenpayUtil.getTimestamp();
            string nonceStr  = TenpayUtil.getNoncestr();

            RequestHandler Params = new RequestHandler(Context);

            Params.setParameter("appid", TenpayUtil.appid);
            Params.setParameter("appkey", TenpayUtil.appkey);
            Params.setParameter("noncestr", nonceStr);
            Params.setParameter("timestamp", timeStamp);
            Params.setParameter("productid", productid);
            string sign = Params.createSHA1Sign();

            Params.setParameter("sign", sign);


            parm = "weixin://wxpay/bizpayurl?sign=" + sign + "&appid=" + TenpayUtil.appid + "&productid=" + productid + "&timeStamp=" + timeStamp + "&nonceStr=" + nonceStr;
            parm = QRfromGoogle(parm);
        }
예제 #27
0
        public UnifiedOrderResult UnifiedOrderByNative(WxAppInfoConfig config, string merchantId, string orderSn, decimal orderAmount, string goods_tag, string ip, string body, DateTime time_expire)
        {
            var ret = new UnifiedOrderResult();

            TenpayUtil tenpayUtil = new TenpayUtil(config);

            UnifiedOrder unifiedOrder = new UnifiedOrder();

            unifiedOrder.openid           = "";
            unifiedOrder.out_trade_no     = orderSn;                            //商户订单号
            unifiedOrder.spbill_create_ip = ip;                                 //终端IP
            unifiedOrder.total_fee        = Convert.ToInt32(orderAmount * 100); //标价金额
            unifiedOrder.body             = body;                               //商品描述
            unifiedOrder.trade_type       = "NATIVE";
            unifiedOrder.time_expire      = time_expire.ToString("yyyyMMddHHmmss");
            unifiedOrder.goods_tag        = goods_tag;
            unifiedOrder.attach           = "{\"merchantId\":\"" + merchantId + "\"}";
            ret = tenpayUtil.UnifiedOrder(unifiedOrder);

            return(ret);
        }
예제 #28
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int             site_payment_id = 0;                                                 //站点支付方式ID
            ResponseHandler resHandler      = new ResponseHandler(Context);                      //创建ResponseHandler实例
            string          notify_id       = resHandler.getParameter("notify_id");              //通知id
            string          out_trade_no    = resHandler.getParameter("out_trade_no").ToUpper(); //商户订单号
            string          transaction_id  = resHandler.getParameter("transaction_id");         //财付通订单号
            string          total_fee       = resHandler.getParameter("total_fee");              //金额,以分为单位
            string          discount        = resHandler.getParameter("discount");               //如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee
            string          trade_state     = resHandler.getParameter("trade_state");            //支付结果

            if (out_trade_no.StartsWith("R"))                                                    //充值订单
            {
                site_payment_id = new BLL.user_recharge().GetPaymentId(out_trade_no);
            }
            else if (out_trade_no.StartsWith("B")) //商品订单
            {
                site_payment_id = new BLL.orders().GetPaymentId(out_trade_no);
            }
            //找到站点支付方式ID开始验证
            if (site_payment_id > 0)
            {
                TenpayUtil config = new TenpayUtil(site_payment_id);
                resHandler.setKey(config.key);
                //判断签名
                if (resHandler.isTenpaySign())
                {
                    if ("0".Equals(trade_state))
                    {
                        //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                        Response.Redirect(new Web.UI.BasePage().linkurl("payment", "?action=succeed&order_no=" + out_trade_no));
                        return;
                    }
                }
            }
            //认证签名失败
            Response.Redirect(new Web.UI.BasePage().linkurl("payment", "?action=error"));
            return;
        }
예제 #29
0
        /// <summary>
        /// NATIVE第二种扫码支付
        /// </summary>
        /// <returns></returns>
        public string Code()
        {
            //根据什么生成订单号   价格  商品名称  附加信息

            UnifiedOrder order = new UnifiedOrder();

            order.appid       = tenpay.WeChartConfigItem.appid;
            order.attach      = "vinson1";
            order.body        = "极客美家NATIVE支付正式测试";//订单描述
            order.device_info = "";
            order.mch_id      = tenpay.WeChartConfigItem.mch_id;
            order.nonce_str   = TenpayUtil.getNoncestr();                                                                   //随机字符串
            order.notify_url  = "http://mobile.mj100.com/test/h?id=100";                                                    //回调网址

            order.out_trade_no     = "20156666978542323" + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString(); //订单号
            order.trade_type       = "NATIVE";
            order.spbill_create_ip = Request.UserHostAddress;
            order.total_fee        = 1;
            //order.total_fee = 1;
            string Code_url = tenpay.TenpayUtil.getCode_url(order, tenpay.WeChartConfigItem.key);//商户key

            return(Code_url);
        }
예제 #30
0
        /// <summary>
        /// 获取分享参数信息
        /// </summary>
        /// <param name="url">分销Url</param>
        /// <param name="config">配置信息</param>
        /// <returns>结果</returns>
        public static TokenInfo GetWeiXinShareConfig(string url, Config config)
        {
            var jtCache = string.Empty; //Redis.GetRedis<string>(Config.JsapiTicket);

            if (string.IsNullOrEmpty(jtCache))
            {
                var jsapiTicketUrl = TenpayUtil.GetJsapiTicketUrl(config, false);
                var jsapiTicket    = JsonConvert.DeserializeObject <JsapiTicket>(HttpHelp.GetUrl(jsapiTicketUrl));
                if (jsapiTicket.Errcode == 0)
                {
                    jtCache = jsapiTicket.Ticket;
                    //Redis.SetRedis(Config.JsapiTicket, jsapiTicket.ticket, DateTime.Now.AddSeconds(jsapiTicket.expires_in - 2));
                }
                else
                {
                    var jsapiTicketUrl1 = TenpayUtil.GetJsapiTicketUrl(config, true);
                    var jsapiTicket1    = JsonConvert.DeserializeObject <JsapiTicket>(HttpHelp.GetUrl(jsapiTicketUrl1));
                    jtCache = jsapiTicket1.Ticket;
                }
            }
            var info = TenpayUtil.GetConfigInfo(jtCache, url, config);

            return(info);
        }