Esempio n. 1
0
        /// <summary>
        /// 生成支付所需信息 url json等
        /// </summary>
        /// <param name="payment">付款信息</param>
        /// <param name="exts">其他参数信息</param>
        /// <returns></returns>
        public override string Pay(Payment payment, params string[] exts)
        {
            //测试 正式删除 开始
            payment.Id          = "X" + getRandomValidate(8);//"5950483";
            payment.Subject     = "test";
            payment.Amount      = 0.01m;
            Platform.MerchantId = "2088501709692126";
            Platform.NotifyUrl  = "http://shopping.tiantian.com/ToPay/MobilePayMent/APPPay/ZhiFuBaoCallBack.aspx";

            var payId  = payment.Id;//系统订单号
            var amount = payment.Amount.ToString("F2");

            var body = "test-body";
            //测试 正式删除 结束

            var param = new Dictionary <string, string>();

            // 支付宝支付接口必需参数 参数顺序必需固定且与react native里android一致 因为签名原因
            param.Add("service", "mobile.securitypay.pay");//接口名称,固定值
            param.Add("partner", Platform.MerchantId);
            param.Add("_input_charset", Charset);

            param.Add("notify_url", Platform.NotifyUrl);
            param.Add("out_trade_no", payId);
            param.Add("subject", payment.Subject);       //商品的标题/交易标题/订单标题/订单关键字等。该参数最长为128个汉字。
            param.Add("payment_type", PaymentType);
            param.Add("seller_id", Platform.MerchantId); //卖家支付宝账号(邮箱或手机号码格式)或其对应的支付宝唯一用户号(以2088开头的纯16位数字)
            param.Add("total_fee", amount);
            param.Add("body", body);                     //对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body

            //connect = "partner=2088501709692126&[email protected]&out_trade_no=5950483&subject=订单编号5950483&body=订单编号5950483&total_fee=17.9&notify_url=http://shopping.tiantian.com/ToPay/MobilePayMent/APPPay/ZhiFuBaoCallBack.aspx&service=mobile.securitypay.pay&_input_charset=utf-8&payment_type=1&return_url=http://www.tiantian.com&it_b_pay=1d&show_url=http://www.tiantian.com";

            var sign = UrlEncoder.Default.Encode(CreateSign(param));

            var output = new PaymentParam();

            output.Add("partner", Platform.MerchantId);
            output.Add("seller", Platform.MerchantId);
            output.Add("outTradeNO", payId);
            output.Add("subject", payment.Subject);
            output.Add("body", body);
            output.Add("totalFee", amount);
            output.Add("notifyURL", Platform.NotifyUrl);
            output.Add("sign", sign);
            return(output.ToJson());//生成适用于react-native json格式的数据


            /* 2.0
             * // 支付宝支付接口必需参数
             * param.Add("app_id", "2015010900024452");
             * param.Add("method", "alipay.trade.app.pay");
             * param.Add("charset", Charset);
             * param.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
             * param.Add("version", "1.0");
             * param.Add("notify_url", Platform.NotifyUrl);
             *
             *
             * var biz = new PaymentParam();
             * biz.Add("out_trade_no", payment.Id);
             * biz.Add("subject", payment.Subject);
             * biz.Add("body", body);
             * biz.Add("total_amount", amount);
             * biz.Add("product_code", "QUICK_MSECURITY_PAY");
             *
             * param.Add("biz_content", biz.ToJson());
             *
             * var sign = CreateSign(param);
             *
             * param.Add("sign", sign);
             * param.Add("sign_type", SignType);
             *
             *
             * var output = param.ToQueryString(false, true, true);
             * return output;
             */


            /*
             * param.Add("privateKey", Platform.PrivateKey);
             * param.Add("partner", Platform.MerchantId);
             * param.Add("seller", SellerId);
             * param.Add("outTradeNO", payId);
             * param.Add("body", body);
             * param.Add("totalFee", amount);
             * param.Add("notifyURL", Platform.NotifyUrl);
             * param.Add("itBPay", "30m");//设置未付款交易的超时时间,一旦超时,该笔交易就会自动被关闭。当用户输入支付密码、点击确认付款后(即创建支付宝交易后)开始计时。取值范围:1m~15d,或者使用绝对时间(示例格式:2014-06-13 16:00:00)。m-分钟,h-小时,d-天,1c-当天(1c-当天的情况下,无论交易何时创建,都在0点关闭)。该参数数值不接受小数点,如1.5h,可转换为90m。
             * return param.ToJson();//生成适用于https://github.com/huangzuizui/rn-alipay json格式的数据
             */
        }
Esempio n. 2
0
        private string Pay(Payment payment, string tradeType, string openId)
        {
            var param = new PaymentParam();

            param.Add("appid", Platform.PublicKey);                        //微信分配的公众账号ID(企业号corpid即为此appId)
            param.Add("mch_id", Platform.MerchantId);                      //微信支付分配的商户号
            param.Add("nonce_str", GenerateNonceStr());                    //随机字符串,不长于32位
            param.Add("body", payment.Subject);                            //商品简单描述 该字段须严格按照规范传递

            param.Add("attach", payment.State);                            //附加数据 在查询API和支付通知中原样返回 该字段主要用于商户携带订单的自定义数据
            param.Add("out_trade_no", payment.Id);                         //商户系统内部的订单号,32个字符内 可包含字母
            param.Add("total_fee", (payment.Amount * 100).ToString("F0")); //订单总金额,单位为分 不能带小数
            param.Add("spbill_create_ip", payment.IpAddress);              //APP和网页支付提交用户端ip Native支付填调用微信支付API的机器IP
            param.Add("notify_url", Platform.NotifyUrl);
            param.Add("trade_type", tradeType);
            if (tradeType == "NATIVE")
            {
                param.Add("product_id", payment.Id);// trade_type = NATIVE 时 此参数必传 此id为二维码中包含的商品ID,商户自行定义
            }
            if (tradeType == "JSAPI")
            {
                param.Add("openid", openId);// rade_type=JSAPI 时此参数必传 用户在商户appid下的唯一标识
            }

            param.Add("sign", CreateSign(param));

            PaymentParam data;//支付接口返回参数

            using (Client)
            {
                var xml = param.ToXml();//微信接口接受xml格式的数据

                OnTraced("微信支付 提交数据", xml);

                var hc     = new StringContent(xml, Encoding.UTF8, "text/xml");
                var rep    = Client.PostAsync(Platform.GatewayUrl, hc).Result;
                var repXml = XElement.Load(rep.Content.ReadAsStreamAsync().Result);

                OnTraced("微信支付 返回数据", repXml.ToString());

                data = new PaymentParam(repXml);
            }

            var s = string.Empty;

            if (data.GetString("return_code") == "SUCCESS" && data.GetString("result_code") == "SUCCESS")
            {
                if (VerifySign(data))
                {
                    if (tradeType == "APP")
                    {
                        var prePayParam = new PaymentParam();
                        var prePayId    = data.GetString("prepay_id");

                        prePayParam.Add("appId", Platform.PublicKey);
                        prePayParam.Add("partnerId", Platform.MerchantId);
                        prePayParam.Add("prepayId", prePayId);
                        prePayParam.Add("package", "Sign=WXPay");
                        prePayParam.Add("nonceStr", GenerateNonceStr());
                        prePayParam.Add("timeStamp", GenerateTimeStamp());
                        prePayParam.Add("sign", CreateSign(prePayParam));
                        s = prePayParam.ToJson();
                    }
                    else if (tradeType == "JSAPI")
                    {
                        var prePayParam = new PaymentParam();
                        var prePayId    = data.GetString("prepay_id");

                        prePayParam.Add("appId", Platform.PublicKey);
                        prePayParam.Add("timeStamp", GenerateTimeStamp());
                        prePayParam.Add("nonceStr", GenerateNonceStr());
                        prePayParam.Add("package", "prepay_id=" + prePayId);
                        prePayParam.Add("signType", "MD5");
                        prePayParam.Add("paySign", CreateSign(prePayParam));
                        s = prePayParam.ToJson();
                    }
                    else if (tradeType == "NATIVE")
                    {
                        s = data.GetString("code_url");//用于生成微信客户端可识别的支付URL
                    }
                }
                else
                {
                    var err = data.GetString("err_code_des");
                    var msg = string.IsNullOrEmpty(err) ? data.GetString("return_msg") : err;
                    OnTraced("微信支付 验证返回数据签名失败", msg);
                }
            }
            return(s);
        }