Example #1
0
        public void TestCreatePreOrder2()
        {
            WeiXinPayChannel channel = new WeiXinPayChannel();

            channel.AppID                  = "wxd930ea5d5a258f4f";
            channel.AppSecret              = "db426a9829e4b49a0dcac7b4162da6b6";
            channel.PaySignKey             = "L8LrMqqeGRxST5reouB0K66CaYAWpqhAVsq7ggKkxHCOastWksvuX1uvmvQclxaHoYd3ElNBrNO2DHnnzgfVG9Qs473M3DTOZug5er46FhuGofumV8H2FVR9qkjSlC5K";
            channel.ParnterID              = "1900000109";
            channel.ParnterKey             = "8934e7d15453e97507ef794cf7b0519d";
            channel.NotifyToTradeCenterURL = "http://www.qq.com";

            Package package = new Package()
            {
                Body           = "测试订单",
                NotifyUrl      = "http://www.qq.com",
                OutTradeNo     = "kODvVBBJ3THJ1jMB",
                Partner        = channel.ParnterID,
                SpbillCreateIp = "192.168.0.1",
                TotalFee       = "1"
            };

            WeiXinAppOrderRequest request = new WeiXinAppOrderRequest(channel);

            request.Traceid = "crestxu";
            request.SetPackage(package);

            var rsp        = WeiXinPay4AppGateway.CreatePreOrder(channel, request);
            var rspContent = rsp.ToJSON();

            Console.WriteLine(rspContent);
        }
Example #2
0
        public static PreOrderResponse PreOrder(WeiXinAppOrderRequest pRequest, WeiXinPayChannel pChannel)
        {
            var tokenInfo = GetToken(pChannel);

            if (tokenInfo == null)
            {
                throw new Exception("获取Token失败");
            }
            if (!tokenInfo.IsSuccess)
            {
                throw new Exception(string.Format("获取Token失败:{0} {1}", tokenInfo.ErrorCode, tokenInfo.ErrorMessage));
            }
            var token = tokenInfo.Token;
            var url   = string.Format("{0}?access_token={1}", GetUrl(WeiXinUrlType.AppPreOrder), token);

            return(CallAPI <PreOrderResponse>(url, pRequest.GetContent()));
        }