李维强-15级 发表于 2017-9-11 22:07:48

住哲API

以下是C#源码,调用参数均在源码上面

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Security.Cryptography;
using System.Net;
using System.Web;
using System.Configuration;

namespace ZhuZheAPI
{
    class Program
    {
      static void Main(string[] args)
      {
            string url = "http://open.zhuzher.com/api/request.action"; //
            string method = "zhuzher.member.rechargeMember2";
            string cId = "C0935201";
            string hotelId = "209412";
            long time = new DateTime().currentTimeMillis();
            string key = "123456";
            string dataKey = "12345678";
            string authCode = funcMD5(cId+method+time+key);


            string inputObj = getRoomPrice();   //在此下断,即可看到XML请求参数
            inputObj = desCrypto(inputObj, dataKey);
            inputObj = Uri.EscapeDataString(inputObj);
            //下面拼好请求字符串
            string queryString = "cId=" + cId + "&authCode=" + authCode + "&method=" + method + "&time=" + time + "&data=" + inputObj;

            byte[] PostData = Encoding.UTF8.GetBytes(queryString);
            WebClient webClient = new WebClient();
            webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            byte[] ResponseData = webClient.UploadData(url, "POST", PostData);
            string SrcString = Encoding.UTF8.GetString(ResponseData);
            Console.WriteLine(SrcString);       //在此下断即可看到返回值

            XmlDocument xml = new XmlDocument();
            xml.LoadXml(SrcString);
         // xml.SelectSingleNode("")

      }


      public static string getRoomPrice()
      {
            XmlDocument XmlDoc = new XmlDocument();

            //加入根节点 request
            XmlElement rootElement = XmlDoc.CreateElement("request");
            XmlDoc.AppendChild(rootElement);

            XmlElement headElement = XmlDoc.CreateElement("head");
            headElement.InnerText = "";
            rootElement.AppendChild(headElement);

            XmlElement bodyElement = XmlDoc.CreateElement("body");

            XmlElement hotelIdElement = XmlDoc.CreateElement("hotelId");
            hotelIdElement.InnerText = "209412";
            bodyElement.AppendChild(hotelIdElement);

            XmlElement roomTypeID = XmlDoc.CreateElement("roomTypeId");
            roomTypeID.InnerText = "";//此处文档说 非必填,但是填不填都一样
            bodyElement.AppendChild(roomTypeID);

            XmlElement startDate = XmlDoc.CreateElement("startDate");
            startDate.InnerText = DateTime.Now.ToString("yyyy-MM-dd");
            bodyElement.AppendChild(startDate);

            XmlElement endtDate = XmlDoc.CreateElement("endDate");
            endtDate.InnerText = DateTime.Now.AddHours(25).ToString("yyyy-MM-dd");
            bodyElement.AppendChild(endtDate);

            XmlElement comefrom = XmlDoc.CreateElement("comefrom"); //此处专门看了的 都是小写,但是改为之前的格式comeFrom也不行
            comefrom.InnerText = "802";
            bodyElement.AppendChild(comefrom);


            rootElement.AppendChild(bodyElement);

            return XmlDoc.OuterXml;

      }
      public static string GetHotelInfo()
      {
            XmlDocument XmlDoc = new XmlDocument();

            //加入根节点 request
            XmlElement rootElement = XmlDoc.CreateElement("request");
            XmlDoc.AppendChild(rootElement);

            XmlElement headElement = XmlDoc.CreateElement("head");
            headElement.InnerText = "";
            rootElement.AppendChild(headElement);

            XmlElement bodyElement = XmlDoc.CreateElement("body");
            XmlElement hotelIdElement = XmlDoc.CreateElement("hotelId");
            hotelIdElement.InnerText = "209412";
            bodyElement.AppendChild(hotelIdElement);

            rootElement.AppendChild(bodyElement);

            return XmlDoc.OuterXml;


      }

      public static string funcMD5(string sDataIn)
      {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] bytValue, bytHash;
            bytValue = System.Text.Encoding.UTF8.GetBytes(sDataIn);
            bytHash = md5.ComputeHash(bytValue);
            md5.Clear();
            string sTemp = "";
            for (int i = 0; i < bytHash.Length; i++)
            {
                sTemp += bytHash.ToString("X").PadLeft(2, '0');
            }
            return sTemp.ToLower();
      }


      public static string desCrypto(string datasource,string password)
      {
            DESCryptoServiceProvider objDESCryptoServiceProvider = new DESCryptoServiceProvider();
            objDESCryptoServiceProvider.Key = Encoding.UTF8.GetBytes(password);
            objDESCryptoServiceProvider.IV = Encoding.UTF8.GetBytes(password);
            objDESCryptoServiceProvider.Mode = CipherMode.ECB;
            objDESCryptoServiceProvider.Padding = PaddingMode.PKCS7;

            byte[] bysData = Encoding.UTF8.GetBytes(datasource);
            byte[] bysFixSizeData = new byte[(int)(Math.Ceiling(bysData.Length/8.0)*8)];
            Array.Copy(bysData, bysFixSizeData, bysData.Length);
            byte[] bysEncrypted = objDESCryptoServiceProvider.CreateEncryptor().TransformFinalBlock(bysFixSizeData, 0, bysFixSizeData.Length);
            return Convert.ToBase64String(bysEncrypted);
      }


    }
    /// <summary>
    /// DeteTime扩展方法,达到java里面System.currentTimeMillis()功能
    /// </summary>
    public static class DateTimeExtend
    {
      private static DateTime GMTIni = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
      public static long currentTimeMillis(this DateTime d)
      {
            return (long)((DateTime.UtcNow - GMTIni).TotalMilliseconds);
      }
    }


}


下面图示程序流程关键位置,可以看到调用参数正确,但是返回结果异常,请技术查一下原因


李维强-15级 发表于 2017-10-22 22:56:36

[
{
    "domain": "15923051435.oicp.net",
    "expirationDate": 1540219837.502758,
    "hostOnly": true,
    "httpOnly": false,
    "name": "headimgurl",
    "path": "/",
    "sameSite": "no_restriction",
    "secure": false,
    "session": false,
    "storeId": "0",
    "value": "http://wx.qlogo.cn/mmopen/vi_32/7wQ88slwA95jNenMcAyC75WxIR3tKkV6Yej5YoVdywN0nSeHeicjZVq2G5j8v25nVDtUBRPoBOSVHibJ8p9cd8Bg/0",
    "id": 1
},
{
    "domain": "15923051435.oicp.net",
    "expirationDate": 1540219837.502759,
    "hostOnly": true,
    "httpOnly": false,
    "name": "nickname",
    "path": "/",
    "sameSite": "no_restriction",
    "secure": false,
    "session": false,
    "storeId": "0",
    "value": "squall",
    "id": 2
},
{
    "domain": "15923051435.oicp.net",
    "expirationDate": 1540219837.502757,
    "hostOnly": true,
    "httpOnly": false,
    "name": "openid",
    "path": "/",
    "sameSite": "no_restriction",
    "secure": false,
    "session": false,
    "storeId": "0",
    "value": "ootlZwda9ehK2ypgSbrR7PTF6vug",
    "id": 3
}
]

李维强-15级 发表于 2017-10-25 03:24:55

预定调用方法
string method = "zhuzher.order.submitOrder";
      public static string SubmitOrder2()
      {
            XmlDocument XmlDoc = new XmlDocument();

            XmlElement rootElement = XmlDoc.CreateElement("request");
            XmlDoc.AppendChild(rootElement);

            XmlElement headElement = XmlDoc.CreateElement("head");
            headElement.InnerText = "";
            rootElement.AppendChild(headElement);

            XmlElement bodyElement = XmlDoc.CreateElement("body");

            XmlElement hotelIdElement = XmlDoc.CreateElement("hotelId");
            hotelIdElement.InnerText = "210883";
            bodyElement.AppendChild(hotelIdElement);

            XmlElement roomTypeId = XmlDoc.CreateElement("roomTypeId");
            roomTypeId.InnerText = "1944";      //测试房间ID
            bodyElement.AppendChild(roomTypeId);

            XmlElement roomTypeName = XmlDoc.CreateElement("roomTypeName");
            roomTypeName.InnerText = "测试";
            bodyElement.AppendChild(roomTypeName);

            XmlElement startDate = XmlDoc.CreateElement("startTime");
            startDate.InnerText = DateTime.Now.AddHours(10).ToString("yyyy-MM-dd HH:mm:ss");
            bodyElement.AppendChild(startDate);

            XmlElement endStart = XmlDoc.CreateElement("endTime");
            endStart.InnerText = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss");
            bodyElement.AppendChild(endStart);

            XmlElement roomNum = XmlDoc.CreateElement("roomNum");
            roomNum.InnerText = "1";
            bodyElement.AppendChild(roomNum);

            XmlElement ratePlanId = XmlDoc.CreateElement("ratePlanId");
            ratePlanId.InnerText = "";
            bodyElement.AppendChild(ratePlanId);

            XmlElement bookPerson = XmlDoc.CreateElement("bookPerson");
            bookPerson.InnerText = "李维强";
            bodyElement.AppendChild(bookPerson);

            XmlElement bookTel = XmlDoc.CreateElement("bookTel");
            bookTel.InnerText = "15923051435";
            bodyElement.AppendChild(bookTel);

            XmlElement bookemail = XmlDoc.CreateElement("bookEmail");
            bookemail.InnerText = "";
            bodyElement.AppendChild(bookemail);

            XmlElement checkInPerson = XmlDoc.CreateElement("checkInPerson");
            checkInPerson.InnerText = "李维强";
            bodyElement.AppendChild(checkInPerson);

            XmlElement checkInTel = XmlDoc.CreateElement("checkInTel");
            checkInTel.InnerText = "15923051435";
            bodyElement.AppendChild(checkInTel);

            XmlElement cardNo = XmlDoc.CreateElement("cardNo");
            cardNo.InnerText = "";
            bodyElement.AppendChild(cardNo);

            XmlElement comefrom = XmlDoc.CreateElement("comefrom");
            comefrom.InnerText = "5";
            bodyElement.AppendChild(comefrom);

            XmlElement keepTime = XmlDoc.CreateElement("keepTime");
            keepTime.InnerText = "23:59";
            bodyElement.AppendChild(keepTime);

            XmlElement totalPrice = XmlDoc.CreateElement("totalPrice");
            totalPrice.InnerText = "1";
            bodyElement.AppendChild(totalPrice);

            XmlElement ensureFlag = XmlDoc.CreateElement("ensureFlag");
            ensureFlag.InnerText = "0";   //表示已支付定金
            bodyElement.AppendChild(ensureFlag);

            XmlElement guarantorType = XmlDoc.CreateElement("guarantorType");
            guarantorType.InnerText = "无担保";
            bodyElement.AppendChild(guarantorType);

            XmlElement remark = XmlDoc.CreateElement("remark");
            remark.InnerText = "测试订房备注";
            bodyElement.AppendChild(remark);

            //XmlElement xxx = XmlDoc.CreateElement("xxx");
            //xxx.InnerText = "xxx";
            //orderItem.AppendChild(xxx);

            rootElement.AppendChild(bodyElement);

            return XmlDoc.OuterXml;

      }


      public static string SubmitOrder()
      {
            XmlDocument XmlDoc = new XmlDocument();

            XmlElement rootElement = XmlDoc.CreateElement("request");
            XmlDoc.AppendChild(rootElement);

            XmlElement headElement = XmlDoc.CreateElement("head");
            headElement.InnerText = "";
            rootElement.AppendChild(headElement);

            XmlElement bodyElement = XmlDoc.CreateElement("body");

            XmlElement hotelIdElement = XmlDoc.CreateElement("hotelId");
            hotelIdElement.InnerText = "210883";
            bodyElement.AppendChild(hotelIdElement);

            XmlElement bookPerson = XmlDoc.CreateElement("bookPerson");
            bookPerson.InnerText = "李维强";
            bodyElement.AppendChild(bookPerson);

            XmlElement bookTel = XmlDoc.CreateElement("bookTel");
            bookTel.InnerText = "15923051435";
            bodyElement.AppendChild(bookTel);

            XmlElement ensureFlag = XmlDoc.CreateElement("ensureFlag");
            ensureFlag.InnerText = "1";   //表示已支付定金
            bodyElement.AppendChild(ensureFlag);

            XmlElement guarantorType = XmlDoc.CreateElement("guarantorType");
            guarantorType.InnerText = "";
            bodyElement.AppendChild(guarantorType);

            XmlElement remark = XmlDoc.CreateElement("remark");
            remark.InnerText = "测试订房备注";
            bodyElement.AppendChild(remark);

            XmlElement bookemail = XmlDoc.CreateElement("bookemail");
            bookemail.InnerText = "";
            bodyElement.AppendChild(bookemail);

            XmlElement bookNum = XmlDoc.CreateElement("bookNum");
            bookNum.InnerText = "";
            bodyElement.AppendChild(bookNum);

            XmlElement keepTime = XmlDoc.CreateElement("keepTime");
            keepTime.InnerText = "18:00";
            bodyElement.AppendChild(keepTime);

            XmlElement totalPrice = XmlDoc.CreateElement("totalPrice");
            totalPrice.InnerText = "2";
            bodyElement.AppendChild(totalPrice);

            for (int i = 0; i < 2; i++)
            {

                XmlElement orderItem = XmlDoc.CreateElement("orderItem");
            orderItem.InnerText = "";
            bodyElement.AppendChild(orderItem);

         



                XmlElement startDate = XmlDoc.CreateElement("startDate");
                startDate.InnerText = DateTime.Now.ToString("yyyy-MM-dd 12:00:00");
                orderItem.AppendChild(startDate);

                XmlElement endStart = XmlDoc.CreateElement("endStart");
                endStart.InnerText = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 12:00:00");
                orderItem.AppendChild(endStart);

                XmlElement roomTypeId = XmlDoc.CreateElement("roomTypeId");
                roomTypeId.InnerText = "1944";      //测试房间ID
                orderItem.AppendChild(roomTypeId);

                XmlElement roomTypeName = XmlDoc.CreateElement("roomTypeName");
                roomTypeName.InnerText = "测试";
                orderItem.AppendChild(roomTypeName);

                XmlElement checkInPerson = XmlDoc.CreateElement("checkInPerson");
                checkInPerson.InnerText = "李维强";
                orderItem.AppendChild(checkInPerson);

                XmlElement checkInTel = XmlDoc.CreateElement("checkInTel");
                checkInTel.InnerText = "15923051435";
                orderItem.AppendChild(checkInTel);

                XmlElement cardNo = XmlDoc.CreateElement("cardNo");
                cardNo.InnerText = "";
                orderItem.AppendChild(cardNo);

                XmlElement ratePlanId = XmlDoc.CreateElement("ratePlanId");
                ratePlanId.InnerText = "";
                orderItem.AppendChild(ratePlanId);

                //bodyElement.AppendChild(orderItem);


            }
            //XmlElement xxx = XmlDoc.CreateElement("xxx");
            //xxx.InnerText = "xxx";
            //orderItem.AppendChild(xxx);

            rootElement.AppendChild(bodyElement);

            return XmlDoc.OuterXml;

      }

李维强-15级 发表于 2017-10-26 17:04:02

本帖最后由 李维强-15级 于 2017-11-24 19:16 编辑

<?xml version="1.0"?>
-<response>
<head/>
-<body>
<memberCardNo>2171</memberCardNo>
-<result>
<code>1</code>
<errorMsg>调用成功!</errorMsg>
</result>
</body>
</response>


住哲推送返回数据

<message>
<head serviceCode="ORDE002" messageCode="f91e9e2f-40b2-4d02-9cc0-6090dae7ced0" createTime="1511520121455"></head>
<body>
<chainId>09352</chainId>
<hotelId>210883</hotelId>
<orderId>1490669</orderId>
<bookPerson>李维强</bookPerson>
<bookTel>15923051435</bookTel>
<ensureFlag>1</ensureFlag>
<guarantorType>全程担保</guarantorType>
<orderDate>2017-11-18 01:18:42</orderDate>
<bookNum>null</bookNum>
<orderItem>
<startDate>2017-11-18 12:00:00.0</startDate>
<endStart>2017-11-19 12:00:00.0</endStart>
<roomTypeId>1944</roomTypeId>
<roomTypeName>测试</roomTypeName>
<checkInPerson>李维强</checkInPerson>
<checkInTel>15923051435</checkInTel>
<price>1</price>
<comefrom>网站会员</comefrom>
</orderItem></body></message>

<message><head serviceCode="ROOM001" messageCode="eb271853-be0d-4048-9766-17e88168c9a5" createTime="1511521617716"></head><body><checkIn>
<hotelId>209412</hotelId>
<roomTypeId>1155</roomTypeId>
<roomTypeName>逸_园景大床房</roomTypeName>
<roomNo>320</roomNo>
<price>598</price>
<startTime>2017-11-24 19:05:57</startTime>
<orderId>1499786</orderId>
<houseType>0</houseType>
<customer>
    <customerItem>
      <customerId>1620441</customerId>
      <memberNo>H1074102</memberNo>
      <customerName>胡育贤</customerName>
      <sex>male</sex>
      <idCardType>newidentitycard</idCardType>
      <idCardNo></idCardNo>
      <birthDate></birthDate>
      <provice></provice>
      <address></address>
      <interest></interest>
      <telNo>13695007268</telNo>
      <email></email>
    </customerItem>
</customer>
</checkIn></body></message>
页: [1]
查看完整版本: 住哲API