支付宝小程序开发系列三: 统一下单支付(.net)

第一步:后台构造统一下单参数(SDK:https://download.csdn.net/download/qq_36894527/12875709)

/// <summary>
        /// 支付宝统一下单接口
        /// </summary>
        /// <param name="appid"></param>
        /// <param name="merchant_private_key">应用私钥</param>
        /// <param name="alipay_public_key">支付宝公钥</param>
        /// <param name="user_id">user_id</param>
        /// <param name="total_fee"></param>
        /// <param name="bill"></param>
        /// <returns></returns>
        public static string TradePay(string appid, string merchant_private_key ,string alipay_public_key,string notifyurl,string user_id, string total_fee, string bill)
        {
            decimal fee = decimal.Round(decimal.Parse(total_fee), 2);
            string result = "";
            try
            {
                IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", appid, merchant_private_key, "json", "1.0", "RSA2", alipay_public_key, "GBK", false);
                AlipayTradeCreateRequest request = new AlipayTradeCreateRequest();
                request.SetNotifyUrl(notifyUrl);
                request.BizContent = "{" +
                "\"out_trade_no\":\"" + bill + "\"," +
                //"\"seller_id\":\"\"," +
                "\"total_amount\":\"" + fee + "\"," +
                //"\"discountable_amount\":0," +
                "\"subject\":\"会员充值\"," +
                //"\"body\":\"支付宝会员充值\"," +
                "\"buyer_id\":\"" + user_id+ "\"" +
                 //"      \"goods_detail\":[{" +
                 //"        \"goods_id\":\"apple-01\"," +
                 //"\"goods_name\":\"ipad\"," +
                 //"\"quantity\":1," +
                 //"\"price\":2000," +
                 //"\"goods_category\":\"34543238\"," +
                 //"\"categories_tree\":\"124868003|126232002|126252004\"," +
                 //"\"body\":\"特价手机\"," +
                 //"\"show_url\":\"http://www.alipay.com/xxx.jpg\"" +
                 //"        }]," +
                 //"\"product_code\":\"FACE_TO_FACE_PAYMENT\"," +
                 //"\"operator_id\":\"Yx_001\"," +
                 //"\"store_id\":\"NJ_001\"," +
                 //"\"terminal_id\":\"NJ_T_001\"," +
                 //"\"extend_params\":{" +
                 //"\"sys_service_provider_id\":\"2088511833207846\"," +
                 //"\"card_type\":\"S0JP0000\"" +
                 //"    }," +
                 //"\"timeout_express\":\"90m\"," +
                 //"\"settle_info\":{" +
                 //"        \"settle_detail_infos\":[{" +
                 //"          \"trans_in_type\":\"cardAliasNo\"," +
                 //"\"trans_in\":\"A0001\"," +
                 //"\"summary_dimension\":\"A0001\"," +
                 //"\"settle_entity_id\":\"2088xxxxx;ST_0001\"," +
                 //"\"settle_entity_type\":\"SecondMerchant、Store\"," +
                 //"\"amount\":0.1" +
                 //"          }]," +
                 //"\"settle_period_time\":\"7d\"" +
                 //"    }," +
                 //"\"logistics_detail\":{" +
                 //"\"logistics_type\":\"EXPRESS\"" +
                 //"    }," +
                 //"\"business_params\":{" +
                 //"\"campus_card\":\"0000306634\"," +
                 //"\"card_type\":\"T0HK0000\"," +
                 //"\"actual_order_time\":\"2019-05-14 09:18:55\"" +
                 //"    }," +
                 //"\"receiver_address_info\":{" +
                 //"\"name\":\"张三\"," +
                 //"\"address\":\"上海市浦东新区陆家嘴银城中路501号\"," +
                 //"\"mobile\":\"13120180615\"," +
                 //"\"zip\":\"200120\"," +
                 //"\"division_code\":\"310115\"" +
                 //"    }" +
                 "  }";
                AlipayTradeCreateResponse response = client.Execute(request);
                Console.WriteLine(response.Body);
                JObject jobj = (JObject)JsonConvert.DeserializeObject(response.Body);
                if (jobj["alipay_trade_create_response"]["code"].ToString() == "10000")
                {
                    string trade_no = jobj["alipay_trade_create_response"]["trade_no"].ToString();
                    result = ReturnInfo.CodeReturn("S",trade_no);
                }
                else
                {
                    string msg = jobj["alipay_trade_create_response"]["msg"].ToString();
                    result = ReturnInfo.CodeReturn("E", msg);
                }
            }
            catch (Exception ex)
            {
                result = ReturnInfo.CodeReturn("E", ex.Message);
            }
            return result;
        }

第二步:小程序发起支付

 my.tradePay({
            tradeNO: res,//后台返回的支付宝交易单号
            success: function (res) {}
});

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值