// 懒人版,如果不想添加Request,Response,Model。可以用这种方式,返回Dictionary<string, object>,后续自己处理 private static void TestCommon() { // 创建请求对象 CommonRequest request = new CommonRequest("alipay.story.find"); // 请求参数 Dictionary <string, string> bizModel = new Dictionary <string, string> { ["name"] = "白雪公主" }; request.BizModel = bizModel; // 发送请求 CommonResponse response = client.Execute(request); if (response.IsSuccess()) { // 返回结果 string body = response.Body; Dictionary <string, object> dict = JsonUtil.ParseToDictionary(body); Console.WriteLine("Dictionary内容:"); foreach (var item in dict) { Console.WriteLine("{0}:{1}", item.Key, item.Value); } } else { Console.WriteLine("错误, code:{0}, msg:{1}, subCode:{2}, subMsg:{3}", response.Code, response.Msg, response.SubCode, response.SubMsg); } }
public void TestLazy() { // 接口请求 CommonRequest request = new CommonRequest("goods.get"); // 请求参数 Dictionary <string, object> param = new Dictionary <string, object>(); // 属性赋值 param["goods_name"] = "iphone6"; // 设置请求参数 request.Param = param; // 发送请求,返回结果 CommonResponse response = client.Execute <CommonResponse>(request); if (response.IsSuccess()) { Assert.IsTrue(response.data is Dictionary <string, object>); Assert.IsTrue(response.data["goods_name"].ToString() == "苹果iPhoneX"); } else { throw new SystemException(response.msg); } }