Example #1
0
        /// <summary>
        /// 申请退款
        /// </summary>
        /// <param name="inputObj">提交给申请退款API的参数</param>
        /// <param name="CertPath">证书路径</param>
        /// <param name="CertPassword">证书密码</param>
        /// <param name="timeOut">超时时间</param>
        /// <returns></returns>
        public PaymentData Refund(PaymentData inputObj, int timeOut = 6)
        {
            string url = "https://api.mch.weixin.qq.com/secapi/pay/refund";

            //检测必填参数
            if (!inputObj.IsSet("out_trade_no") && !inputObj.IsSet("transaction_id"))
            {
                throw new Exception("退款申请接口中,out_trade_no、transaction_id至少填一个!");
            }
            else if (!inputObj.IsSet("out_refund_no"))
            {
                throw new Exception("退款申请接口中,缺少必填参数out_refund_no!");
            }
            else if (!inputObj.IsSet("total_fee"))
            {
                throw new Exception("退款申请接口中,缺少必填参数total_fee!");
            }
            else if (!inputObj.IsSet("refund_fee"))
            {
                throw new Exception("退款申请接口中,缺少必填参数refund_fee!");
            }
            else if (!inputObj.IsSet("op_user_id"))
            {
                throw new Exception("退款申请接口中,缺少必填参数op_user_id!");
            }

            inputObj.SetValue("appid", AppId);                                          //公众账号ID
            inputObj.SetValue("mch_id", MchId);                                         //商户号
            inputObj.SetValue("nonce_str", Guid.NewGuid().ToString().Replace("-", "")); //随机字符串
            inputObj.SetValue("sign", inputObj.MakeSign(SignKey));                      //签名
            string xml      = inputObj.ToXml();
            string response = HttpService.Post(xml, url, true, timeOut, CertPath, CertPassword);
            //将xml格式的结果转换为对象以返回
            PaymentData result = new PaymentData();

            result.FromXml(response);
            return(result);
        }
Example #2
0
        /// <summary>
        /// 企业付款接口
        /// </summary>
        /// <param name="inputObj">参数</param>
        /// <param name="CertPath">证书路径</param>
        /// <param name="CertPassword">证书密码</param>
        /// <param name="timeOut">超时时间</param>
        /// <returns></returns>
        public PaymentData Transfers(PaymentData inputObj, int timeOut = 6)
        {
            string url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";

            #region 检测必要参数

            //检测必填参数
            if (!inputObj.IsSet("partner_trade_no") && !inputObj.IsSet("partner_trade_no"))
            {
                throw new Exception("企业付款接口中,缺少必填参数partner_trade_no!");
            }
            if (!inputObj.IsSet("openid"))
            {
                throw new Exception("企业付款接口中,缺少必填参数openid!");
            }
            if (!inputObj.IsSet("check_name"))
            {
                throw new Exception("企业付款接口中,缺少必填参数check_name!");
            }
            else
            {
                string checkName = inputObj.GetValue("check_name").ToString();
                switch (checkName)
                {
                case "FORCE_CHECK":
                case "OPTION_CHECK":
                    if (!inputObj.IsSet("check_name"))
                    {
                        throw new Exception("企业付款接口中,缺少必填参数re_user_name!");
                    }
                    break;

                default:
                    break;
                }
            }
            if (!inputObj.IsSet("amount"))
            {
                throw new Exception("企业付款接口中,缺少必填参数amount!");
            }
            if (!inputObj.IsSet("desc"))
            {
                throw new Exception("企业付款接口中,缺少必填参数desc!");
            }
            if (!inputObj.IsSet("spbill_create_ip"))
            {
                throw new Exception("企业付款接口中,缺少必填参数spbill_create_ip!");
            }
            #endregion

            #region 添加公共参数
            inputObj.SetValue("mch_appid", AppId);                                      //公众账号ID
            inputObj.SetValue("mchid", MchId);                                          //商户号
            inputObj.SetValue("spbill_create_ip", Ip);                                  //随机字符串
            inputObj.SetValue("nonce_str", Guid.NewGuid().ToString().Replace("-", "")); //随机字符串
            inputObj.SetValue("sign", inputObj.MakeSign(SignKey));                      //签名
            #endregion
            string      xml      = inputObj.ToXml();
            var         start    = DateTime.Now;
            string      response = HttpService.Post(xml, url, true, timeOut, CertPath, CertPassword);
            PaymentData result   = new PaymentData();
            result.FromXml(response);

            return(result);
        }