示例#1
0
        /// <summary>
        ///     普通红包发送
        /// </summary>
        public NormalRedPackResult SendNormalRedPack(NormalRedPackRequest model)
        {
            //发红包接口地址
            var url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";

            NormalRedPackResult result = null;

            try
            {
                model.WxAppId = WeChatConfig.AppId;
                model.MchId   = PayConfig.MchId;
                //本地或者服务器的证书位置(证书在微信支付申请成功发来的通知邮件中)
                var cert = PayConfig.PayCertPath;
                //私钥(在安装证书时设置)
                var password = PayConfig.CertPassword;

                //调用证书
                var cer = new X509Certificate2(cert, password,
                                               X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet);
                //ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                //X509Certificate cer = new X509Certificate(cert, password);

                var dictionary = PayUtil.GetAuthors(model);
                model.Sign = PayUtil.CreateMd5Sign(dictionary, PayConfig.TenPayKey); //生成Sign
                //var dict = PayUtil.GetAuthors(model);

                result = PostXML <NormalRedPackResult>(url, model, cer);
            }
            catch (Exception ex)
            {
                WeChatHelper.LoggerAction?.Invoke(nameof(RedPackApi), ex.ToString());
            }
            return(result);
        }
示例#2
0
文件: Pay.cs 项目: netnr/blog
        /// <summary>
        /// 公共API => 测速上报
        /// 不需要证书
        /// http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_8
        ///应用场景
        ///商户在调用微信支付提供的相关接口时,会得到微信支付返回的相关信息以及获得整个接口的响应时间。为提高整体的服务水平,
        ///协助商户一起提高服务质量,微信支付提供了相关接口调用耗时和返回信息的主动上报接口,微信支付可以根据商户侧上报的数据进一步优化网络部署,完善服务监控,和商户更好的协作为用户提供更好的业务体验。
        /// </summary>
        /// <param name="appid">(必填) String(32) 微信分配的公众账号ID</param>
        /// <param name="mch_id">(必填) String(32) 微信支付分配的商户号</param>
        /// <param name="device_info"> String(32) 微信支付分配的终端设备号,商户自定义</param>
        /// <param name="nonce_str">(必填) 随机字符串 随机字符串,不长于32位。</param>
        /// <param name="interface_url">String(127) 接口URL  上报对应的接口的完整URL,类似:
        ///https://api.mch.weixin.qq.com/pay/unifiedorder
        ///对于被扫支付,为更好的和商户共同分析一次业务行为的整体耗时情况,对于两种接入模式,请都在门店侧对一次被扫行为进行一次单独的整体上报,上报URL指定为:
        ///https://api.mch.weixin.qq.com/pay/micropay/total
        ///关于两种接入模式具体可参考本文档章节:被扫支付商户接入模式
        ///其它接口调用仍然按照调用一次,上报一次来进行。
        /// </param>
        /// <param name="execute_time_">Int  接口耗时   接口耗时情况,单位为毫秒 </param>
        /// <param name="return_code">String(16)  返回状态码   接口耗时情况,单位为毫秒 </param>
        /// <param name="return_msg">String(128)  返回信息    返回信息,如非空,为错误原因 :签名失败; 参数格式校验错误 </param>
        /// <param name="result_code">String(16)  业务结果    SUCCESS/FAIL </param>
        /// <param name="err_code">String(32)  错误代码   </param>
        /// <param name="err_code_des">String(128)  错误代码描述</param>
        /// <param name="out_trade_no">String(32)  商户订单号 商户系统内部的订单号,商户可以在上报时提供相关商户订单号方便微信支付更好的提高服务质量。 </param>
        /// <param name="user_ip">String(16)  访问接口IP   发起接口调用时的机器IP  </param>
        /// <param name="time">String(14)  商户上报时间 系统时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。 其他详见第4.2节时间规则:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=4_2  </param>
        /// <param name="partnerKey">API密钥</param>
        /// <returns> 参见:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_8 </returns>
        public static string RefundQuery(string appid, string mch_id, string device_info, string nonce_str,
                                         string interface_url, string execute_time_,
                                         string return_code, string return_msg, string result_code, string err_code,
                                         string err_code_des, string out_trade_no, string user_ip, string time,
                                         string partnerKey)
        {
            var stringADict = new Dictionary <string, string>
            {
                { "appid", appid },
                { "mch_id", mch_id },
                { "device_info", device_info },
                { "nonce_str", nonce_str },
                { "interface_url", interface_url },
                { "execute_time_", execute_time_ },
                { "return_code", return_code },
                { "return_msg", return_msg },
                { "result_code", result_code },
                { "err_code", err_code },
                { "err_code_des", err_code_des },
                { "out_trade_no", out_trade_no },
                { "user_ip", user_ip },
                { "time", time }
            };

            var sign     = PayUtil.Sign(stringADict, partnerKey);//生成签名字符串
            var postdata = PayUtil.GeneralPostdata(stringADict, sign);
            var url      = "https://api.mch.weixin.qq.com/pay/refundquery";

            var result = NetnrCore.HttpTo.Post(url, postdata);

            return(result);
        }
示例#3
0
            /// <summary>
            /// 公共API => 申请退款
            /// 需要双向证书
            /// http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_4
            ///应用场景
            ///当交易发生之后一段时间内,由于买家或者卖家的原因需要退款时,卖家可以通过退款接口将支付款退还给买家,微信支付将在收到退款请求并且验证成功之后,按照退款规则将支付款按原路退到买家帐号上。
            ///注意:
            ///1.交易时间超过半年的订单无法提交退款;
            ///2.微信支付退款支持单笔交易分多次退款,多次退款需要提交原支付订单的商户订单号和设置不同的退款单号。一笔退款失败后重新提交,要采用原来的退款单号。总退款金额不能超过用户实际支付金额。
            ///3.接口提交成功后,还需要在微信商户后台由商户管理员审核退款
            /// </summary>
            /// <param name="appid">(必填) String(32) 微信分配的公众账号ID</param>
            /// <param name="mch_id">(必填) String(32) 微信支付分配的商户号</param>
            /// <param name="device_info"> String(32) 微信支付分配的终端设备号,商户自定义</param>
            /// <param name="nonce_str">(必填) 随机字符串 随机字符串,不长于32位。</param>
            /// <param name="transaction_id">String(32) 微信订单号 微信的订单号,优先使用 </param>
            /// <param name="out_trade_no">(transaction_id为空时必填) String(32) 商户订单号 transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no </param>
            /// <param name="out_refund_no">(必填) String(32) 商户退款单号 商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔 </param>
            /// <param name="total_fee">(必填) int 总金额 订单总金额,单位为分,只能为整数。 </param>
            /// <param name="refund_fee">(必填) int  退款金额 退款总金额,订单总金额,单位为分,只能为整数</param>
            /// <param name="refund_fee_type">String(8) 货币种类 符合ISO 4217标准的三位字母代码,默认人民币:CNY</param>
            /// <param name="op_user_id">(必填) String(32) 操作员 操作员帐号, 默认为商户号mch_id </param>
            /// <param name="partnerKey">API密钥</param>
            /// <returns> 参见:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_4 </returns>
            public static string Refund(string appid, string mch_id, string device_info, string nonce_str,
                                        string transaction_id, string out_trade_no, string out_refund_no,
                                        int total_fee, int refund_fee, string refund_fee_type, string op_user_id,
                                        string partnerKey)
            {
                var stringADict = new Dictionary <string, string>
                {
                    { "appid", appid },
                    { "mch_id", mch_id },
                    { "device_info", device_info },
                    { "nonce_str", nonce_str },
                    { "transaction_id", transaction_id },
                    { "out_trade_no", out_trade_no },
                    { "out_refund_no", out_refund_no },
                    { "total_fee", total_fee.ToString() },
                    { "refund_fee", refund_fee.ToString() },
                    { "refund_fee_type", refund_fee_type },
                    { "op_user_id", op_user_id }
                };

                var sign     = PayUtil.Sign(stringADict, partnerKey);//生成签名字符串
                var postdata = PayUtil.GeneralPostdata(stringADict, sign);
                var url      = "https://api.mch.weixin.qq.com/secapi/pay/refund";

                var result = HttpTo.Post(url, postdata);

                return(result);
            }
示例#4
0
        /// <summary>
        ///     支付交易返回失败或支付系统超时,调用该接口撤销交易。如果此订单用户支付失败,微信支付系统会将此订单关闭;如果用户支付成功,微信支付系统会将此订单资金退还给用户。
        ///     注意:7天以内的交易单可调用撤销,其他正常支付的单如需实现相同功能请调用申请退款API。提交支付交易后调用【查询订单API】,没有明确的支付结果再调用【撤销订单API】。
        ///     调用支付接口后请勿立即调用撤销订单API,建议支付后至少15s后再调用撤销订单接口。
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ReverseResult Reverse(ReverseRequest model)
        {
            var url = "https://api.mch.weixin.qq.com/secapi/pay/reverse";

            ReverseResult result = null;

            try
            {
                var wechatConfig = WeChatConfig;
                model.Appid     = wechatConfig.AppId;
                model.Mch_id    = PayConfig.MchId;
                model.Nonce_str = PayUtil.GetNoncestr();
                //本地或者服务器的证书位置(证书在微信支付申请成功发来的通知邮件中)
                var cert = PayConfig.PayCertPath;
                //私钥(在安装证书时设置)
                var password = PayConfig.CertPassword;

                //调用证书
                var cer = new X509Certificate2(cert, password,
                                               X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet);

                var dictionary = PayUtil.GetAuthors(model);
                model.Sign = PayUtil.CreateMd5Sign(dictionary, PayConfig.TenPayKey); //生成Sign
                result     = PostXML <ReverseResult>(url, model, cer);
            }
            catch (Exception ex)
            {
                WeChatHelper.LoggerAction?.Invoke(nameof(TenPayV3), ex.ToString());
            }
            return(result);
        }
示例#5
0
            public void ProcessRequest(HttpContext context)
            {
                netpay = new CmsNetpayHandle();
                form   = context.Request.Form;
                string action = context.Request["action"];

                if (action == "submit")
                {
                    context.Response.Write(Submit());
                }
                else if (action == "test")
                {
                    SortedDictionary <string, string> dict = new SortedDictionary <string, string>();
                    dict.Add("action", "submit");
                    dict.Add("order_no", String.Empty.RandomLetters(10));
                    dict.Add("pmid", "1");
                    dict.Add("ptid", "3");
                    dict.Add("order_fee", "0.01");
                    dict.Add("order_exp_fee", "0");
                    dict.Add("show_url", "");
                    dict.Add("receive_name", "");
                    dict.Add("receive_address", "");
                    dict.Add("receive_zip", "");
                    dict.Add("receive_phone", "");
                    dict.Add("receive_mobile", "");

                    context.Response.Write(
                        PayUtil.GetGatewaySubmit(context.Request.Path, dict)
                        );
                }
            }
示例#6
0
        public EnterpriseResult EnterprisePayment(EnterpriseRequest model)
        {
            //发红包接口地址
            var url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";

            EnterpriseResult result = null;

            try
            {
                var wechatConfig = WeChatConfig;
                model.MchAppId = wechatConfig.AppId;
                model.MchId    = PayConfig.MchId;
                //本地或者服务器的证书位置(证书在微信支付申请成功发来的通知邮件中)
                var cert = PayConfig.PayCertPath;
                //私钥(在安装证书时设置)
                var password = PayConfig.CertPassword;

                //调用证书
                var cer = new X509Certificate2(cert, password,
                                               X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet);

                var dictionary = PayUtil.GetAuthors(model);
                model.Sign = PayUtil.CreateMd5Sign(dictionary, PayConfig.TenPayKey); //生成Sign

                result = PostXML <EnterpriseResult>(url, model, cer);
            }
            catch (Exception ex)
            {
                WeChatHelper.LoggerAction?.Invoke(nameof(EnterprisePayApi), ex.ToString());
            }
            return(result);
        }
示例#7
0
文件: Pay.cs 项目: netnr/blog
        /// <summary>
        /// 提交被扫支付API
        /// http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=5_5
        /// 1.应用场景:收银员使用扫码设备读取微信用户刷卡授权码以后,二维码或条码信息传送至商户收银台,由商户收银台或者商户后台调用该接口发起支付。
        ///是否需要证书:不需要。
        /// <param name="appid">(必填) String(32) 微信分配的公众账号ID</param>
        /// <param name="mch_id">(必填) String(32) 微信支付分配的商户号</param>
        /// <param name="device_info"> String(32) 微信支付分配的终端设备号,商户自定义</param>
        /// <param name="nonce_str">(必填) String(32) 随机字符串,不长于32位</param>
        /// <param name="body">(必填) String(32) 商品描述 商品或支付单简要描</param>
        /// <param name="detail"> String(8192) 商品详情  商品名称明细列表</param>
        /// <param name="attach"> String(127) 附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据</param>
        /// <param name="out_trade_no">(必填) String(32) 商家订单ID,32个字符内、可包含字母, 其他说明见第4.2节商户订单号:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=4_2 </param>
        /// <param name="fee_type">符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见第4.2节货币类型: http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=4_2 </param>
        /// <param name="total_fee">(必填) Int 订单总金额,只能为整数,详见第4.2节支付金额:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=4_2 </param>
        /// <param name="spbill_create_ip">(必填) String(32)终端IP APP和网页支付提交用户端IP,Native支付填调用微信支付API的机器IP。</param>
        /// <param name="time_start">String(14) 订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。</param>
        /// <param name="time_expire">String(14) 订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。</param>
        /// <param name="goods_tag">String(32) 商品标记,代金券或立减优惠功能的参数,说明详见第10节代金券或立减优惠:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=10_1 </param>
        /// <param name="auth_code">String(128) 授权码 扫码支付授权码,设备读取用户微信中的条码或者二维码信息 </param>
        /// <param name="partnerKey">API密钥</param>
        /// </summary>
        /// <returns>返回json字符串,格式参见:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=5_5 </returns>
        public static string MicroPay(string appid, string mch_id, string device_info,
                                      string nonce_str, string body, string detail, string attach,
                                      string out_trade_no, string fee_type, int total_fee, string spbill_create_ip,
                                      string time_start, string time_expire, string goods_tag,
                                      string auth_code,
                                      string partnerKey)
        {
            var stringADict = new Dictionary <string, string>
            {
                { "appid", appid },
                { "mch_id", mch_id },
                { "device_info", device_info },
                { "nonce_str", nonce_str },
                { "body", body },
                { "attach", attach },
                { "out_trade_no", out_trade_no },
                { "fee_type", fee_type },
                { "total_fee", total_fee.ToString() },
                { "spbill_create_ip", spbill_create_ip },
                { "time_start", time_start },
                { "time_expire", time_expire },
                { "goods_tag", goods_tag },
                { "auth_code", auth_code }
            };
            var sign     = PayUtil.Sign(stringADict, partnerKey);//生成签名字符串
            var postdata = PayUtil.GeneralPostdata(stringADict, sign);
            var url      = "https://api.mch.weixin.qq.com/pay/micropay";

            var result = NetnrCore.HttpTo.Post(url, postdata);

            return(result);
        }
示例#8
0
        /// <summary>
        /// 发放普通红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_1
        /// </summary>
        /// <param name="appid"></param>
        /// <param name="mch_id"></param>
        /// <param name="nonce_str"></param>
        /// <param name="partner_trade_no"></param>
        /// <param name="openid"></param>
        /// <param name="send_name"></param>
        /// <param name="amount"></param>
        /// <param name="total_num"></param>
        /// <param name="wishing"></param>
        /// <param name="client_ip"></param>
        /// <param name="act_name"></param>
        /// <param name="remark"></param>
        /// <param name="partnerKey"></param>
        /// <param name="cert"></param>
        /// <param name="certPassword"></param>
        /// <param name="scene_id"></param>
        /// <param name="risk_info"></param>
        /// <param name="consume_mch_id"></param>
        /// <returns></returns>
        public static string Sendredpack(string appid, string mch_id, string nonce_str, string partner_trade_no,
                                         string openid, string send_name, int amount, int total_num, string wishing, string client_ip, string act_name,
                                         string remark, string partnerKey, string cert, string certPassword,
                                         string scene_id = "", string risk_info = "", string consume_mch_id = "")
        {
            var stringADict = new Dictionary <string, string>
            {
                { "nonce_str", nonce_str },
                { "mch_billno", partner_trade_no },
                { "mch_id", mch_id },
                { "wxappid", appid },
                { "send_name", send_name },
                { "re_openid", openid },
                { "total_amount", amount.ToString() },
                { "total_num", total_num.ToString() },
                { "wishing", wishing },
                { "client_ip", client_ip },
                { "act_name", act_name },
                { "remark", remark }
            };

            if (!string.IsNullOrEmpty(scene_id))
            {
                stringADict.Add("scene_id", scene_id);
            }
            if (!string.IsNullOrEmpty(risk_info))
            {
                stringADict.Add("risk_info", risk_info);
            }
            if (!string.IsNullOrEmpty(consume_mch_id))
            {
                stringADict.Add("consume_mch_id", consume_mch_id);
            }

            var sign                    = PayUtil.Sign(stringADict, partnerKey);//生成签名字符串
            var postdata                = PayUtil.GeneralPostdata(stringADict, sign);
            var url                     = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";
            X509Certificate2 cer        = new(cert, certPassword);
            Encoding         encoding   = Encoding.UTF8;
            HttpWebRequest   webrequest = (HttpWebRequest)WebRequest.Create(url);

            webrequest.ClientCertificates.Add(cer);
            byte[] bs = encoding.GetBytes(postdata);
            webrequest.Method        = "POST";
            webrequest.ContentType   = "application/x-www-form-urlencoded";
            webrequest.ContentLength = bs.Length;
            using (Stream reqStream = webrequest.GetRequestStream())
            {
                reqStream.Write(bs, 0, bs.Length);
                reqStream.Close();
            }
            using (HttpWebResponse response = (HttpWebResponse)webrequest.GetResponse())
            {
                using (StreamReader reader = new(response.GetResponseStream(), encoding))
                {
                    var resXml = reader.ReadToEnd().ToString();
                    return(resXml);
                }
            }
        }
        /// <summary>
        /// 退款申请接口
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public RefundResult Refund(RefundRequest model)
        {
            var url = "https://api.mch.weixin.qq.com/secapi/pay/refund";

            RefundResult result = null;

            try
            {
                var wechatConfig = WeChatConfig;
                model.AppId      = wechatConfig.AppId;
                model.Mch_Id     = PayConfig.MchId;
                model.NonceStr   = PayUtil.GetNoncestr();
                model.Op_user_id = PayConfig.MchId;

                //本地或者服务器的证书位置(证书在微信支付申请成功发来的通知邮件中)
                var cert = HostingEnvironment.ApplicationPhysicalPath + PayConfig.PayCertPath;
                //私钥(在安装证书时设置)
                var password = PayConfig.CertPassword;

                //调用证书
                var cer = new X509Certificate2(cert, password,
                                               X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet);

                var dictionary = PayUtil.GetAuthors(model);
                WeChatHelper.PayLogger.Log(LoggerLevels.Error, model.Total_fee);
                model.Sign = PayUtil.CreateMd5Sign(dictionary, PayConfig.TenPayKey); //生成Sign
                result     = PostXML <RefundResult>(url, model, cer);
            }
            catch (Exception ex)
            {
                WeChatHelper.PayLogger.Log(LoggerLevels.Error, ex);
            }
            return(result);
        }
示例#10
0
        public ActionResult TestPay()
        {
            #region 统一下单

            LogManager.GetCurrentClassLogger().Debug("开始下单");
            var model = new UnifiedorderRequest {
                OpenId = WeiChatApplicationContext.Current.WeiChatUser.OpenId
            };
            LogManager.GetCurrentClassLogger().Debug(JsonConvert.SerializeObject(model.OpenId));
            model.SpbillCreateIp = "8.8.8.8";
            model.OutTradeNo     = PayUtil.GenerateOutTradeNo();
            model.TotalFee       = "1";
            model.NonceStr       = PayUtil.GetNoncestr();
            model.TradeType      = "JSAPI";
            model.Body           = "购买商品";
            model.DeviceInfo     = "WEB";
            var result = WeChatApisContext.Current.TenPayV3Api.Unifiedorder(model);

            var _dict = new Dictionary <string, string>
            {
                { "appId", result.AppId },
                { "timeStamp", PayUtil.GetTimestamp() },
                { "nonceStr", result.NonceStr },
                { "package", "prepay_id=" + result.PrepayId },
                { "signType", "MD5" }
            };
            _dict.Add("paySign", PayUtil.CreateMd5Sign(_dict, WeChatConfigManager.Current.GetPayConfig().TenPayKey));

            #endregion

            ViewBag.PayPam = JsonConvert.SerializeObject(_dict);
            return(View());
        }
示例#11
0
        public void ActiveDevice()
        {
            DateTime dtime = DateTime.Now;

            PayUtil.ActiveDevice(new ActiveDeviceDto {
                activeCode = "4EB019"
            });
        }
示例#12
0
 public void Query()
 {
     PayUtil.Query(new QueryDto
     {
         out_trade_no = "201705241546180565",
         terminal_id  = "153254"
     });
 }
示例#13
0
        /// <summary>
        /// </summary>
        /// <param name="page"></param>
        /// <param name="inputStream"></param>
        /// <returns></returns>
        public NotifyResult Notify(Stream inputStream)
        {
            NotifyResult result = null;
            var          data   = PayUtil.PostInput(inputStream);

            result = XmlHelper.DeserializeObject <NotifyResult>(data);
            return(result);
        }
示例#14
0
 public CancelResponse CancelOrder(string out_trade_no, string terminal_id)
 {
     return(PayUtil.Cancel(new CancelDto
     {
         out_trade_no = out_trade_no,
         terminal_id = terminal_id,
     }));
 }
示例#15
0
 public QueryResponse QueryOrder(string out_trade_no, string terminal_id)
 {
     return(PayUtil.Query(new QueryDto
     {
         out_trade_no = out_trade_no,
         terminal_id = terminal_id
     }));
 }
示例#16
0
 public void Refund()
 {
     PayUtil.Refund(new RefundDto
     {
         out_trade_no  = "201705241546180565",
         terminal_id   = "153254",
         refund_amount = "10"
     });
 }
示例#17
0
 public RefundResponse RefundOrder(string out_trade_no, string terminal_id, int refundAmount)
 {
     return(PayUtil.Refund(new RefundDto
     {
         out_trade_no = out_trade_no,
         terminal_id = terminal_id,
         refund_amount = refundAmount.ToString()
     }));
 }
示例#18
0
 public CasherOpersResponse CasherOperate(string casherName, string casherPwd)
 {
     return(PayUtil.CasherOper(new CasherOpersDto
     {
         casher_name = casherName,
         casher_pwd = casherPwd,
         operatore_type = OperType.Create.GetHashCode().ToString()
     }));
 }
示例#19
0
        public PaidHandleResult Return <T>(PayMointor <T> proc) where T : class
        {
            SortedDictionary <string, string> sPara = PayUtil.GetRequestGet();
            var request = HttpContext.Current.Request;

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                Notify aliNotify    = new Notify();
                bool   verifyResult = aliNotify.Verify(sPara, request.QueryString["notify_id"], request.QueryString["sign"]);

                if (verifyResult)//验证成功
                {
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //请在这里加上商户的业务逻辑程序代码


                    //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                    //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表

                    //商户订单号

                    string out_trade_no = request.QueryString["out_trade_no"];

                    //支付宝交易号

                    string trade_no = request.QueryString["trade_no"];

                    //交易状态
                    string trade_status = request.QueryString["trade_status"];

                    proc.Init(out_trade_no);


                    if (request.QueryString["trade_status"] == "WAIT_SELLER_SEND_GOODS")
                    {
                        //判断该笔订单是否在商户网站中已经做过处理
                        //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                        //如果有做过处理,不执行商户的业务程序

                        return(PaidHandleResult.Success);
                    }
                    else
                    {
                        return(PaidHandleResult.Fail);
                    }
                }
                else//验证失败
                {
                    return(PaidHandleResult.Fail);
                }
            }
            else
            {
                return(PaidHandleResult.Fail);
            }
        }
示例#20
0
        public void AddCasher()
        {
            DateTime dtime = DateTime.Now;

            PayUtil.CasherOper(new CasherOpersDto
            {
                casher_name    = "自助机测试2",
                casher_pwd     = "123456",
                operatore_type = OperType.Create.GetHashCode().ToString()
            });
        }
示例#21
0
        public PaidHandleResult Return <T>(PayMointor <T> proc) where T : class
        {
            // http://www.jin-ec.com/mapfre/pay/notify?body=%E8%AE%A2%E5%8D%952013122345312
            // &buyer_email=newmin.net%40gmail.com&buyer_id=2088302384317810&exterface=create_direct_pay_by_user
            // &is_success=T&notify_id=RqPnCoPT3K9%252Fvwbh3I75KL02sthKJHtG2dh1Mg5RF5qgJKDY8jd2nu0ChZQAfPMX38xu
            // &notify_time=2013-12-23+14%3A18%3A53&notify_type=trade_status_sync&out_trade_no=2013122345312
            //&payment_type=1&seller_email=clientinfo%40roadchina.com.cn&seller_id=2088201937033268
            //&subject=%E6%98%A5%E8%BF%90%E4%BF%9D%E9%9A%9C%E4%BA%A7%E5%93%81&total_fee=0.01
            // &trade_no=2013122303460581&trade_status=TRADE_SUCCESS&sign=c8c01b5ac095540f0a35d4f7f5831956&sign_type=MD5
            //
            var request = HttpContext.Current.Request;
            SortedDictionary <string, string> sPara = PayUtil.GetRequestGet();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                Notify aliNotify    = new Notify();
                bool   verifyResult = aliNotify.Verify(sPara, request.QueryString["notify_id"], request.QueryString["sign"]);
                if (verifyResult)//验证成功
                {
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //请在这里加上商户的业务逻辑程序代码

                    //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                    //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表
                    string trade_no     = request.QueryString["trade_no"];          //支付宝交易号
                    string order_no     = request.QueryString["out_trade_no"];      //获取订单号
                    string total_fee    = request.QueryString["total_fee"];         //获取总金额
                    string subject      = request.QueryString["subject"];           //商品名称、订单名称
                    string body         = request.QueryString["body"];              //商品描述、订单备注、描述
                    string buyer_email  = request.QueryString["buyer_email"];       //买家支付宝账号
                    string trade_status = request.QueryString["trade_status"];      //交易状态

                    proc.Init(order_no);


                    if (request.QueryString["trade_status"] == "TRADE_FINISHED" || request.QueryString["trade_status"] == "TRADE_SUCCESS")
                    {
                        return(PaidHandleResult.Success);
                    }

                    //打印页面
                    // Response.Write("验证成功<br />");
                    // Response.Write("trade_no=" + trade_no);

                    //——请根据您的业务逻辑来编写程序(以上代码仅作参考)——

                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                }
            }

            return(PaidHandleResult.Fail);
        }
示例#22
0
 public string notifyPay(HttpRequest request, HttpResponse response, Paypayzhu paypayzhu)
 {
     // 保证密钥一致性
     if (PayUtil.checkPayKey(paypayzhu))
     {
         // TODO 做自己想做的
         return("成功了");
     }
     else
     {
         // TODO 该怎么做就怎么做
         return("失败了");
     }
 }
示例#23
0
        /// <summary>
        ///     订单查询接口
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public QueryResult OrderQuery(QueryRequest model)
        {
            var         url    = "https://api.mch.weixin.qq.com/pay/orderquery";
            QueryResult result = null;

            model.Appid     = WeChatConfig.AppId;
            model.Mch_id    = PayConfig.MchId;
            model.Nonce_str = PayUtil.GetNoncestr();
            var dictionary = PayUtil.GetAuthors(model);

            model.Sign = PayUtil.CreateMd5Sign(dictionary, PayConfig.TenPayKey); //生成Sign
            result     = PostXML <QueryResult>(url, model);
            return(result);
        }
示例#24
0
        public void Precreate()
        {
            DateTime dtime = DateTime.Now;

            PayUtil.Precreate(new TradePreCreateDto {
                //discountable_amount="0",
                //undiscountable_amount="10",
                total_amount = "10",
                channel      = PayChannel.Wxpay.GetHashCode().ToString(),
                terminal_id  = "153254",
                operatore_id = "5731",
                out_trade_no = dtime.ToString("yyyyMMddHHmmss") + dtime.Millisecond.ToString().PadLeft(4, '0'),
                subject      = HttpUtility.UrlEncode("测试商品").ToUpper()
            });
        }
示例#25
0
        private void Transfers(string OpenId, int Amount)
        {
            var model = new EnterpriseRequest
            {
                Amount         = Convert.ToInt32(Amount * 100).ToString(),
                CheckName      = "NO_CHECK",
                Desc           = "退货退款",
                DeviceInfo     = "",
                NonceStr       = PayUtil.GetNoncestr(),
                OpenId         = OpenId,
                PartnerTradeNo = PayUtil.GenerateOutTradeNo()
            };

            var relust = WeChatApisContext.Current.EnterprisePayApi.EnterprisePayment(model);
        }
示例#26
0
        /// <summary>
        /// </summary>
        /// <param name="inputStream"></param>
        /// <returns></returns>
        public NotifyResult Notify(Stream inputStream)
        {
            NotifyResult result = null;
            var          data   = PayUtil.PostInput(inputStream);

            try
            {
                result = XmlHelper.DeserializeObject <NotifyResult>(data);
            }
            catch (Exception ex)
            {
                WeChatHelper.LoggerAction?.Invoke(nameof(TenPayV3), ex.ToString());
                throw;
            }
            return(result);
        }
示例#27
0
        public JObject Pay(string type, string price, string redirect, string order_id, string order_info)
        {
            Dictionary <string, string> remote = new Dictionary <string, string>();

            remote.Add("api_user", PayUtil.API_USER);
            remote.Add("price", price);
            remote.Add("type", type);
            remote.Add("redirect", redirect);
            //  remote.Add("order_id", PayUtil.getOrderIdByUUId());
            remote.Add("order_id", order_id);
            remote.Add("order_info", order_info);
            remote.Add("signature", PayUtil.getSignature(PayUtil.API_USER, remote));
            JObject jo = (JObject)JsonConvert.DeserializeObject(PayUtil.GetResponseString(PayUtil.CreatePostHttpResponse("https://www.paypayzhu.com/api/pay_json", remote)));

            return(jo);
        }
示例#28
0
        public JObject order(string order_id)
        {
            Dictionary <string, string> paramMap = new Dictionary <string, string>();

            paramMap.Add("api_user", PayUtil.API_USER);
            paramMap.Add("order_id", order_id);
            string signature = PayUtil.getSignature(PayUtil.API_USER, paramMap);

            // System.out.println(signature);
            paramMap.Add("signature", signature);
            string  idd = PayUtil.GetResponseString(PayUtil.CreatePostHttpResponse("https://www.paypayzhu.com/api/order_query", paramMap));
            JObject jo  = (JObject)JsonConvert.DeserializeObject(PayUtil.GetResponseString(PayUtil.CreatePostHttpResponse("https://www.paypayzhu.com/api/order_query", paramMap)));

            //JSONObject result = PayUtil.post(API_URL + "order_query", paramMap);
            return(jo);
        }
        public IHttpActionResult WechatPay(Guid id)
        {
            try
            {
                //查询订单
                var order =
                    db.Order_Infos.SingleOrDefault(
                        o => (o.Id == id) && (o.OpenId == WeiChatApplicationContext.Current.WeiChatUser.OpenId));
                if (null == order)
                {
                    return(BadRequest("订单信息不存在"));
                }

                #region 统一下单
                var model = new UnifiedorderRequest
                {
                    OpenId         = WeiChatApplicationContext.Current.WeiChatUser.OpenId,
                    SpbillCreateIp = "8.8.8.8",
                    OutTradeNo     = order.Code,
                    TotalFee       = Convert.ToInt32((order.TotalPrice + order.Shipping) * 100).ToString(),
                    NonceStr       = PayUtil.GetNoncestr(),
                    TradeType      = "JSAPI",
                    Body           = "购买商品",
                    DeviceInfo     = "WEB"
                };
                var result = WeChatApisContext.Current.TenPayV3Api.Unifiedorder(model);

                var _dict = new Dictionary <string, string>
                {
                    { "appId", result.AppId },
                    { "timeStamp", PayUtil.GetTimestamp() },
                    { "nonceStr", result.NonceStr },
                    { "package", "prepay_id=" + result.PrepayId },
                    { "signType", "MD5" }
                };
                _dict.Add("paySign", PayUtil.CreateMd5Sign(_dict, WeChatConfigManager.Current.GetPayConfig().TenPayKey));

                #endregion

                return(Ok(_dict));
            }
            catch (Exception ex)
            {
                log.Log(LoggerLevels.Error, "WechatPay:" + ex.Message);
            }
            return(BadRequest("操作失败,请联系管理员!"));
        }
示例#30
0
        public static void Request(string id, decimal amount)
        {
            var name = "" + id + "-Meerkat Store";
            //product description (optional)
            var    body        = "Order from Meerkat Store";
            var    currency    = "USD";
            var    service     = "create_forex_trade";//"create_direct_pay_by_user";
            string signType    = "MD5";
            string key         = Config.key;
            string partner     = Config.partner;
            var    orderId     = id;
            string totalAmount = Math.Round(amount, 2).ToString("0.00", CultureInfo.InvariantCulture);
            string notify_url  = Config.notify_url;
            string return_url  = Config.return_url;

            var param = new Dictionary <string, object>
            {
                { "service", service },
                { "partner", partner },
                { "_input_charset", "utf-8" },
                { "return_url", return_url },
                { "notify_url", notify_url },
                { "currency", currency },
                { "out_trade_no", orderId },
                { "subject", name },
                { "total_fee", totalAmount },
                { "body", body },
            };

            var sign = param.Sign(key);

            var remotePost = new RemotePost
            {
                FormName = "alipaysubmit",
                Url      = PayUtil.GetAlipayUrl(Sandbox) + "?_input_charset=utf-8",
                Method   = "POST"
            };

            foreach (var p in param)
            {
                remotePost.Add(p.Key, p.Value.ToString());
            }
            remotePost.Add("sign", sign);
            remotePost.Add("sign_type", signType);

            remotePost.Post();
        }