Exemplo n.º 1
0
        public void GetJsonStringTest_Null()
        {
            var obj =
                new
                {
                    X =
                        new RootClass()
                        {
                            A = "Jeffrey",
                            B = 31,
                            C = null,
                            ElementClassA = new ElementClass() { A = "Jeffrey", B = null },
                            ElementClassB = null
                        },
                    Y = new
                    {
                        O = "0",
                        Z = (string)null
                    }
                };

            var obj2 = new RootClass()
            {
                A = "Jeffrey",
                B = 31,
                C = null,
                ElementClassA = new ElementClass() { A = "Jeffrey", B = null },
                ElementClassB = null
            };

            var obj3 = new RootClass()
            {
                A = "Jeffrey",
                B = 31,
                C = null,
                ElementClassA = new ElementClass() { A = "Jeffrey", B = null },
                ElementClassB = null,
                ElementClass2 = new ElementClass2()
                {
                    A = "A"
                }
            };

            DateTime dt1 = DateTime.Now;
            SerializerHelper js = new SerializerHelper();

            var json = js.GetJsonString(obj, new JsonSetting(true, new List<string>(new[] { "Z", "C" })));
            Console.WriteLine(json);

            var json2 = js.GetJsonString(obj2, new JsonSetting(true, new List<string>(new[] { "B" })));
            Console.WriteLine(json2);

            var json3 = js.GetJsonString(obj3, new JsonSetting(true, null, new List<Type>(new[] { typeof(ElementClass2) })));
            Console.WriteLine(json3);

            Console.WriteLine((DateTime.Now - dt1).TotalMilliseconds);
        }
        public void GetPreAuthCodeResultTest()
        {
            RegisterTest();//注册

            var preAuthCodeResult = ComponentContainer.GetPreAuthCodeResult(base._appId);
            Assert.IsTrue(preAuthCodeResult.expires_in > 0);

            SerializerHelper serializerHelper=new SerializerHelper();
            Console.Write(serializerHelper.GetJsonString(preAuthCodeResult));
        }
Exemplo n.º 3
0
        public void TestSerialzeEnumString()
        {
            //测试序列化枚举为字符串
            CustomField customField = new CustomField
            {
                 name_type = MemberCard_CustomField_NameType.FIELD_NAME_TYPE_ACHIEVEMEN,
                 url = "http://weixin.senparc.com"
            };

            SerializerHelper serializerHelper = new SerializerHelper();
            JsonSetting jsonSetting = new JsonSetting();
            var jsonString = serializerHelper.GetJsonString(customField, jsonSetting);
            Console.WriteLine(jsonString);
            Assert.IsTrue(jsonString.Contains("FIELD_NAME_TYPE_ACHIEVEMEN"));
            Assert.IsTrue(jsonString.Contains("http://weixin.senparc.com"));

        }
Exemplo n.º 4
0
 /// <summary>
 /// 获取永久素材(除了图文)
 /// </summary>
 /// <param name="accessToken"></param>
 /// <param name="mediaId"></param>
 /// <param name="stream"></param>
 public static void GetForeverMedia(string accessToken, string mediaId, Stream stream)
 {
     var url = string.Format("https://api.weixin.qq.com/cgi-bin/material/get_material?access_token={0}", accessToken.AsUrlData());
     var data = new
     {
         media_id = mediaId
     };
     SerializerHelper serializerHelper = new SerializerHelper();
     var jsonString = serializerHelper.GetJsonString(data);
     Post.Download(url, jsonString, stream);
 }
Exemplo n.º 5
0
        /// <summary>
        /// 目前支持向指定微信用户的openid发放指定金额红包
        /// 注意total_amount、min_value、max_value值相同
        /// total_num=1固定
        /// 单个红包金额介于[1.00元,200.00元]之间
        /// </summary>
        /// <returns></returns>
        public ActionResult SendRedPack()
        {
            string nonceStr;//随机字符串
            string paySign;//签名
            var sendNormalRedPackResult = RedPackApi.SendNormalRedPack(
                TenPayV3Info.AppId, TenPayV3Info.MchId, TenPayV3Info.Key,
                @"F:\apiclient_cert.p12",     //证书物理地址
                "接受收红包的用户的openId",   //接受收红包的用户的openId
                "红包发送者名称",             //红包发送者名称
                Request.UserHostAddress,      //IP
                100,                          //付款金额,单位分
                "红包祝福语",                 //红包祝福语
                "活动名称",                   //活动名称
                "备注信息",                   //备注信息
                out nonceStr,
                out paySign,
                null,                         //场景id(非必填)
                null,                         //活动信息(非必填)
                null                          //资金授权商户号,服务商替特约商户发放时使用(非必填)
                );

            SerializerHelper serializerHelper = new SerializerHelper();
            return Content(serializerHelper.GetJsonString(sendNormalRedPackResult));
        }
Exemplo n.º 6
0
        public void GetJsonStringTest_Expando()
        {
            dynamic test = new ExpandoObject();
            test.x = "Senparc.Weixin SDK";
            test.y = DateTime.Now;

            DateTime dt1 = DateTime.Now;
            SerializerHelper js = new SerializerHelper();

            var json = js.GetJsonString(test);
            Console.WriteLine(json);

            Console.WriteLine((DateTime.Now - dt1).TotalMilliseconds);

        }