예제 #1
0
 public void DownloadTest()
 {
     UploadTest();
     var a = new AccessToken("wxe621f4e5e90b13cd", "7cb56e5b6bd302ddb73c4f76a9ec26a2");
     var m = new MediaManager(a);
     m.Download(mediaId, "C:/1.jpg");
 }
예제 #2
0
        public void GetUserInfo()
        {
            var a = new AccessToken("wxe621f4e5e90b13cd", "7cb56e5b6bd302ddb73c4f76a9ec26a2");
            var m = new UserManager(a);
            var userInfo = m.GetUserInfo("o4mqUjspXEinqvno9XS3RUGEITS8");
            Assert.IsNotNull(userInfo);
            Console.WriteLine(userInfo.NickName);

        }
예제 #3
0
 public void GenerateSquareCode()
 {
     var accessToken = new AccessToken("wxe621f4e5e90b13cd", "7cb56e5b6bd302ddb73c4f76a9ec26a2");
     var s = new PromoteService(accessToken);
     var ticket = s.GenerateSquareCode(1);
     Assert.IsNotNull(ticket);
     Console.WriteLine(ticket);
     Console.WriteLine(System.Web.HttpUtility.UrlEncode(ticket));
 }
예제 #4
0
 public void UploadTest()
 {
     var a = new AccessToken("wx52544b324318b38d", "a8b7e285bbae296f8bbb77e0bf518b1b");
     var m = new MediaManager(a);
     var mediaId = m.Upload(@"C:\Users\maishu\Pictures\100.jpg", MediaType.Image);
     Assert.IsNotNull(mediaId);
     Console.WriteLine(mediaId);
     
     this.mediaId = mediaId;
 }
예제 #5
0
 public void GetJsapiTicket()
 {
     //Id	URL	Token	AppId	AppSecret	ApplicationId	CreateDateTime	IsHide	IsDelete	Remark	AppKey	PartnerId	PartnerKey
     //wxa22b9cfd8fdec01a	d383a6032a4cef3dc22ba9c5130b60e2	7BBFA36C-8115-47AD-8D47-9E52B58E7EFD	2014-06-25 15:46:19.643	0	0	NULL	IUInS0W9rSnhRsF1AC1YZx9TVX5elH2bbRV4wbcEMN8ykdz4r7ht3jyOjqiYYqZcNi1SIig7EVKckcl6eIQs0GdH6BmmbRo5dElL5e9cinlmbnbXhClKbItAAfE0wuCY	1220064601	a09d39a068eda7245dbc8de29e4f2ba5
     //var a = new AccessToken("wxe621f4e5e90b13cd", "7cb56e5b6bd302ddb73c4f76a9ec26a2");
     var a = new AccessToken("wxa22b9cfd8fdec01a", "d383a6032a4cef3dc22ba9c5130b60e2");
     var t = new TicketGenerator(a);
     var js_ticket = t.GetJsapiTicket();
     var s = new YuChang.Core.PromoteService(a);
     for (var i = 10842; i <= 10841 + 20; i++)
     {
         var str = s.GenerateSquareCode(i);
         Console.WriteLine(str);
     }
     //Assert.IsNotNull(js_ticket);
     //Console.WriteLine(js_ticket);
 }
예제 #6
0
        public void SendTest()
        {
            // var appid = "wxa22b9cfd8fdec01a";
            //var secret = "d383a6032a4cef3dc22ba9c5130b60e2";
            var accessToken = new AccessToken("wxa22b9cfd8fdec01a", "d383a6032a4cef3dc22ba9c5130b60e2");
            //var accessToken = new AccessToken("wxe621f4e5e90b13cd", "7cb56e5b6bd302ddb73c4f76a9ec26a2"); //vknew
            //var tmp = new Template("USLehg7XUyraVd2-FevC9NuTvzcCdTdbSnqTOamiZjE", "o1Ux1uGtRiummfXjhZ7vyIqNlzTU");
            var tmp = new Template("USLehg7XUyraVd2-FevC9NuTvzcCdTdbSnqTOamiZjE", "o1Ux1uGtRiummfXjhZ7vyIqNlzTU");
            tmp.Fields.Add(new TemplateField("first", "您好,你的商品已发货"));
            tmp.Fields.Add(new TemplateField("keyword1", "申通快递"));
            tmp.Fields.Add(new TemplateField("keyword2", "1111111111"));
            tmp.Fields.Add(new TemplateField("keyword3", "多个商品"));
            tmp.Fields.Add(new TemplateField("keyword4", "5"));
            tmp.Fields.Add(new TemplateField("remark", "请注意查收。"));

            var m = new TemplateManager(accessToken);
            m.Send(tmp);
        }
예제 #7
0
        public static AccessToken GetAccessToken(string appid, string secret)
        {
            List<AccessToken> accessTokens;
            if (dic_accessTokens.TryGetValue(appid, out accessTokens) == false)
            {
                dic_accessTokens[appid] = accessTokens = new List<AccessToken>();
            }

            string old_secret;
            if (secrets.TryGetValue(appid, out old_secret) == false)
            {
                secrets[appid] = old_secret = secret;
            }

            if (old_secret != secret)
                dic_accessTokens[appid] = new List<AccessToken>();

            AccessToken result;
            for (int i = 0; i < accessTokens.Count; i++)
            {
                if (!accessTokens[i].IsUsing)
                {
                    result = accessTokens[i];
                    return result;
                }
            }
            //if (string.IsNullOrEmpty(AccessTokenPool.AppId))
            //{
            //    throw Error.AppIdIsRequired();
            //}
            //if (string.IsNullOrEmpty(AccessTokenPool.AppSecret))
            //{
            //    throw Error.AppSecretRequired();
            //}
            AccessToken accessToken = new AccessToken(appid, secret);
            accessTokens.Add(accessToken);
            result = accessToken;
            return result;
        }
예제 #8
0
 public ShoppingManager(AccessToken accessToken, string appKey)
 {
     this.accessToken = accessToken;
     this.appKey = appKey;
 }
예제 #9
0
 public CustomMenu(AccessToken accessToken)
 {
     this.accessToken = accessToken;
 }
예제 #10
0
 public PromoteService(AccessToken accessToken)
 {
     this.accessToken = accessToken;
 }
예제 #11
0
 public TemplateManager(AccessToken accessToken)
 {
     this.accessToken = accessToken;
 }
예제 #12
0
            public static void delete(AccessToken token)
            {
                var url = "menu/delete?access_token=" + token;

                weixin.Call(url, new { errcode = "" });
            }
예제 #13
0
            public static void create(AccessToken token, Button[] button)
            {
                var url = string.Format("menu/create?access_token={0}", token);

                weixin.Call(url, new { errcode = "" }, new { button });
            }
예제 #14
0
            public static void api_set_industry(AccessToken token, string industry_id1, string industry_id2)
            {
                var url = "template/api_set_industry?access_token=" + token;

                Call(url, new { errcode = "" }, new { industry_id1, industry_id2 });
            }
예제 #15
0
 public void ToString()
 {
     var accessToken = new AccessToken("wxe621f4e5e90b13cd", "7cb56e5b6bd302ddb73c4f76a9ec26a2");
     var token = accessToken.ToString();
     Assert.IsNotNull(token);
 }
예제 #16
0
            public static getticket_result getticket(AccessToken token, TicketType type)
            {
                var url = "ticket/getticket?type=" + type.ToString() + "&access_token=" + token;

                return(Call(url, new getticket_result()));
            }
예제 #17
0
 public CustomMenu(AccessToken accessToken)
 {
     this.accessToken = accessToken;
 }
예제 #18
0
                /// <summary>
                /// 删除群发【订阅号与服务号认证后均可用】
                /// </summary>
                /// <param name="msg_Id"></param>
                public static void delete(AccessToken token, string msg_Id)
                {
                    var url = "message/mass/send?access_token=" + token;

                    Call(url, new { errorcode = "", errmsg = "" });
                }
예제 #19
0
                /// <summary>
                /// 根据OpenID列表群发【订阅号不可用,服务号认证后可用】
                /// </summary>
                public static string send(AccessToken token, string mediaIdOrContent, MessageType msgtype, string[] touser)
                {
                    if (string.IsNullOrEmpty(mediaIdOrContent))
                    {
                        throw Error.ArugmentNull("mediaIdOrContent");
                    }

                    if (touser == null)
                    {
                        throw Error.ArugmentNull("touser");
                    }

                    if (touser.Length == 0)
                    {
                        var msg = "Length of the touser argument cannt be zero.";
                        throw Error.ArugmentError(msg);
                    }

                    object obj;

                    switch (msgtype)
                    {
                    case MessageType.mpnews:
                        obj = new
                        {
                            touser,
                            mpnews = new { media_id = mediaIdOrContent },
                            msgtype
                        };
                        break;

                    case MessageType.text:
                        obj = new
                        {
                            touser,
                            text = new { content = mediaIdOrContent },
                            msgtype
                        };
                        break;

                    case MessageType.voice:
                        obj = new
                        {
                            touser,
                            voice = new { media_id = mediaIdOrContent },
                            msgtype
                        };
                        break;

                    case MessageType.image:
                        obj = new
                        {
                            touser,
                            image = new { media_id = mediaIdOrContent },
                            msgtype
                        };
                        break;

                    default:
                        var msg = string.Format("'{0}' is a unknown media type", msgtype);
                        throw Error.ArugmentNull(msg);
                    }

                    var serial = new System.Web.Script.Serialization.JavaScriptSerializer();

                    var data = serial.Serialize(obj);

                    var url  = "message/mass/send?access_token=" + token;
                    var json = weixin.GetJson(url, data);
                    var dic  = weixin.Deserialize(json, new { msg_id = "" });

                    return((string)dic.msg_id);
                }
예제 #20
0
                /// <summary>
                /// 根据分组进行群发【订阅号与服务号认证后均可用】
                /// </summary>
                public static string sendall(AccessToken token, string mediaIdOrContent, MessageType msgtype, string group_id)
                {
                    object filter;

                    if (!string.IsNullOrEmpty(group_id))
                    {
                        filter = new { is_to_all = false, group_id };
                    }
                    else
                    {
                        filter = new { is_to_all = true };
                    }

                    object obj;

                    switch (msgtype)
                    {
                    case MessageType.mpnews:
                        obj = new
                        {
                            filter,
                            mpnews = new { media_id = mediaIdOrContent },
                            msgtype
                        };
                        break;

                    case MessageType.text:
                        obj = new
                        {
                            filter,
                            text = new { content = mediaIdOrContent },
                            msgtype
                        };
                        break;

                    case MessageType.voice:
                        obj = new
                        {
                            filter,
                            voice = new { media_id = mediaIdOrContent },
                            msgtype
                        };
                        break;

                    case MessageType.image:
                        obj = new
                        {
                            filter,
                            image = new { media_id = mediaIdOrContent },
                            msgtype
                        };
                        break;

                    default:
                        var msg = string.Format("'{0}' is a unknown media type", msgtype);
                        throw Error.ArugmentNull(msg);
                    }

                    var serial = new System.Web.Script.Serialization.JavaScriptSerializer();

                    var data = serial.Serialize(obj);

                    var url  = "message/mass/sendall?access_token=" + token;
                    var json = weixin.GetJson(url, data);
                    var dic  = weixin.Deserialize(json, new { msg_id = "" });

                    return(dic.msg_id);
                }
예제 #21
0
 public MediaManager(AccessToken accessToken)
 {
     this.accessToken = accessToken;
 }
예제 #22
0
 public MessageProcesser(string appid, string secret, IDbConnection conn)
 {
     this.accessToken = AccessTokenPool.GetAccessToken(appid, secret); //new AccessToken(appid, secret);
     this.conn = conn;
 }
예제 #23
0
 public PromoteService(AccessToken accessToken)
 {
     this.accessToken = accessToken;
 }
예제 #24
0
 public TemplateManager(AccessToken accessToken)
 {
     this.accessToken = accessToken;
 }