Пример #1
0
        /// <summary>
        /// 扫码支付回调URL---扫码支付模式一
        /// </summary>
        /// <returns></returns>
        public string CallbackUrl()
        {
            var result = Pay.GetNotifyData();

            if (string.IsNullOrEmpty(result["openid"].ToString()) || string.IsNullOrEmpty(result["product_id"].ToString()))
            {
                return(Common.SortedDictionaryToXml(Pay.ErrorInfo("回调数据异常")));
            }

            //商户根据productid【在生成二维码时传的是订单号就是订单号,是商品号就是商品号,要对应起来】生成商户系统的订单
            //:TODO

            //统一下单
            var orderParams = new SortedDictionary <string, object>();

            orderParams.Add("appid", ApiModel.AppID);
            orderParams.Add("attach", "微信扫码支付");
            orderParams.Add("body", "扫码支付一测试");
            orderParams.Add("mch_id", ApiModel.MchID);
            orderParams.Add("nonce_str", Common.GetNonceStr());
            orderParams.Add("notify_url", "http://www.liblog.cn/test/pay/payresultnotify"); //支付成功后的回调URl
            orderParams.Add("openid", result["openid"].ToString());
            orderParams.Add("product_id", result["product_id"].ToString());                 //trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。
            orderParams.Add("out_trade_no", Pay.GetOutTradeNo(ApiModel.MchID));             //result["product_id"].ToString()
            orderParams.Add("spbill_create_ip", "171.8.215.143");
            orderParams.Add("total_fee", 1);
            orderParams.Add("trade_type", "NATIVE");
            orderParams.Add("sign", Pay.GetSign(orderParams, ApiModel.MchAPISecret));

            var orderResult = Pay.UnifiedOrder(orderParams);

            //统一下单失败,返回错误结果给微信平台
            if (orderResult["return_code"].ToString() != "SUCCESS")
            {
                return(Common.SortedDictionaryToXml(Pay.ErrorInfo("统一下单失败")));
            }

            //统一下单成功,则返回成功结果给微信支付后台
            var resultParams = new SortedDictionary <string, object>();

            resultParams.Add("return_code", "SUCCESS");
            resultParams.Add("return_msg", "OK");
            resultParams.Add("appid", ApiModel.AppID);
            resultParams.Add("mch_id", ApiModel.MchID);
            resultParams.Add("nonce_str", Common.GetNonceStr());
            resultParams.Add("prepay_id", orderResult["prepay_id"].ToString());
            resultParams.Add("result_code", "SUCCESS");
            resultParams.Add("err_code_des", "OK");
            resultParams.Add("sign", Pay.GetSign(resultParams, ApiModel.MchAPISecret));

            return(Common.SortedDictionaryToXml(resultParams));
        }