Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            log(GetUrlParam(getRequstParam()));
            // log(getRequestString("service"));

            //验证网关
            if ("alipay.service.check".Equals(getRequestString("service")))
            {
                //Response.Output.WriteLine(GetUrlParam());

                verifygw();
            }
            else if ("alipay.mobile.public.message.notify".Equals(getRequestString("service")))
            {
                string eventType   = getXmlNode(getRequestString("biz_content"), "EventType");
                string FromUserId  = getXmlNode(getRequestString("biz_content"), "FromUserId");
                string UserInfo    = getXmlNode(getRequestString("biz_content"), "UserInfo");
                string ActionParam = getXmlNode(getRequestString("biz_content"), "ActionParam");
                string AgreementId = getXmlNode(getRequestString("biz_content"), "AgreementId");
                string AccountNo   = getXmlNode(getRequestString("biz_content"), "AccountNo");
                string AppId       = getXmlNode(getRequestString("biz_content"), "AppId");
                string CreateTime  = getXmlNode(getRequestString("biz_content"), "CreateTime");
                string MsgType     = getXmlNode(getRequestString("biz_content"), "MsgType");

                if ("follow".Equals(eventType))
                {
                    //用户新关注后,可以给用户发送一条欢迎消息,或者引导消息
                    //如:
                    string biz_content = "{\"msgType\":\"image-text\",\"createTime\":\"1407229992\",\"articles\":[{\"actionName\":\"立即查看\",\"desc\":\"描述\",\"imageUrl\":\"https://i.alipayobjects.com/e/201310/1H9ctsy9oN_src.jpg\",\"title\":\"标题\",\"url\":\"http://wap.taobao.com\",\"authType\":\"loginAuth\"},{\"actionName\":\"立即查看\",\"desc\":\"描述\",\"imageUrl\":\"https://i.alipayobjects.com/e/201310/1H9ctsy9oN_src.jpg\",\"title\":\"标题\",\"url\":\"http://wap.taobao.com\",\"authType\":\"loginAuth\"}],\"toUserId\":\"" + FromUserId + "\"}";
                    Response.Output.WriteLine(MessageSendBiz.CustomSend(biz_content));
                }
                else if ("unfollow".Equals(eventType))
                {
                }
                else if ("click".Equals(eventType))
                {
                }
                else if ("enter".Equals(eventType))
                {
                }
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string biz_content = Request.Form.Get("biz_content");
            string response    = null;

            //biz_content的json为示例数据,实际数据需要按照文档组装
            //判断是否有toUserId,如果有,则单发,如果没有,则群发。
            //群发会导致所有人都能收到,一周只能发送一次
            if (biz_content.Contains("\"toUserId\":"))
            {
                response = MessageSendBiz.CustomSend(biz_content);
            }
            else
            {
                response = MessageSendBiz.TotalSend(biz_content);
            }
            IDictionary response_dict = AopUtils.ParseJson(response);

            //输出返回的json
            Response.Output.WriteLine(response);
            Response.End();
        }