예제 #1
0
 /// <summary>
 /// 移动用户分组
 /// </summary>
 /// <param name="openid">用户的OpenID</param>
 /// <param name="groupId">分组id,由微信分配</param>
 /// <returns>RequestResultBaseModel</returns>
 public static RequestResultBaseModel MoveUserToGroup(string openid, int groupId, string access_token)
 {
     if (groupId == null || groupId < 1 || string.IsNullOrEmpty(openid))
     {
         return(new RequestResultBaseModel());
     }
     try
     {
         string url  = Common.ApiUrl + string.Format("groups/members/update?access_token={0}", access_token);
         string data = "{\"openid\":\"OpenId\",\"to_groupid\":GroupID}";
         data = data.Replace("GroupID", groupId.ToString())
                .Replace("OpenId", openid);
         string result = HttpRequestHelper.Request(url, data, HttpRequestHelper.Method.POST, System.Text.Encoding.UTF8);
         if (!string.IsNullOrEmpty(result))
         {
             return(JsonHelper.DeSerialize <WeChatHelper4Net.Models.RequestResultBaseModel>(result));
         }
     }
     catch (Exception Ex)
     {
         LogHelper.Save(Ex, "MoveUserToGroup", LogTime.day);
         throw Ex;
     }
     return(new RequestResultBaseModel());
 }
예제 #2
0
        /// <summary>
        /// 获取永久素材(视频)
        /// </summary>
        /// <param name="ACCESS_TOKEN">访问令牌</param>
        /// <param name="MEDIA_ID"></param>
        /// <returns></returns>
        public static ForeverVideo GetForeverVideo(string ACCESS_TOKEN, string MEDIA_ID)
        {
            if (string.IsNullOrEmpty(MEDIA_ID))
            {
                return(new ForeverVideo());
            }
            try
            {
                string url        = Common.ApiUrl + string.Format("material/get_material?access_token={0}", ACCESS_TOKEN);
                var    jsonString = "{\"media_id\":\"" + MEDIA_ID + "\"}";
                string result     = HttpRequestHelper.Request(url, jsonString, HttpRequestHelper.Method.POST, System.Text.Encoding.UTF8);
                //LogHelper.Save("GetForeverMultimediaVideoStream > " + "ACCESS_TOKEN=" + ACCESS_TOKEN + ",MEDIA_ID=" + MEDIA_ID + ",result=" + result, nameof(Multimedia), LogType.Common, LogTime.day);

                /*
                 * GetForeverMultimediaVideoStream > ACCESS_TOKEN=13_AS8GWsxovYZjCQtLN9CGDrsNCFJeWnEI9hSqX-b99agBMqH75oiZkRsS5b2GWs4AekEj2eKnw4cQcxhn-lafEGHT2Mk7CpwuznIFG05QfFML1Qn7L0uhsKzS7TGF6IxZ4RNb-dxBL3TMb8B4JXHiAFAXLV,MEDIA_ID=8DxY1tadrdbK7TQGFDwTzMNUaJUA79uPtoDPY_Qks4o,result={"title":"第一期-关闭分页预览","description":"","down_url":"http:\/\/mp.weixin.qq.com\/mp\/mp\/video?__biz=MzIxMzc4MTMzMA==&mid=100001728&sn=b9e6258f2abb37028af88bad81976879&vid=o1345teloaj&idx=1&vidsn=5efab83eb152c43d3cfff638d39cc909&fromid=1#rd"}
                 */
                if (!string.IsNullOrEmpty(result))
                {
                    return(JsonHelper.DeSerialize <ForeverVideo>(StringHelper.RemoveSpecialChar(result)));
                }
            }
            catch (Exception Ex)
            {
                LogHelper.Save(Ex);
                throw Ex;
            }
            return(new ForeverVideo());
        }
예제 #3
0
        /// <summary>
        /// 创建自定义菜单
        /// </summary>
        /// <param name="data">创建自定义菜单JSON结构字符串</param>
        /// <returns></returns>
        public static bool CreateMenu(string data, string access_token)
        {
            if (string.IsNullOrEmpty(data))
            {
                return(false);
            }
            try
            {
                string url = Common.ApiUrl + string.Format("menu/create?access_token={0}", access_token);

                string result = HttpRequestHelper.Request(url, data, HttpRequestHelper.Method.POST, System.Text.Encoding.UTF8);
                if (Common.ReturnJSONisOK(result))
                {
                    return(true);
                }
                else
                {
                    RequestResultBaseModel model = JsonHelper.DeSerialize <RequestResultBaseModel>(result);
                    if (model != null && !string.IsNullOrEmpty(model.errmsg) && model.errcode == 0)
                    {
                        return(true);
                    }
                    else
                    {
                        LogHelper.Save("创建自定义菜单失败!    url=" + url + "    data=" + data + "    result=" + result, "CreateMenu", LogType.Error, LogTime.day);
                        return(false);
                    }
                }
            }
            catch (Exception Ex)
            {
                LogHelper.Save(Ex);
                throw Ex;
            }
        }
예제 #4
0
 /// <summary>
 /// 修改分组名
 /// </summary>
 /// <param name="groupId">分组id,由微信分配</param>
 /// <param name="name">分组名字(30个字符以内)</param>
 /// <returns>RequestResultBaseModel</returns>
 public static RequestResultBaseModel UpdateGroupName(int groupId, string name, string access_token)
 {
     if (groupId == null || groupId < 1 || string.IsNullOrEmpty(name))
     {
         return(new RequestResultBaseModel());
     }
     try
     {
         string url  = Common.ApiUrl + string.Format("groups/update?access_token={0}", access_token);
         string data = "{\"group\":{\"id\":GroupID,\"name\":\"GroupName\"}}";
         data = data.Replace("GroupID", groupId.ToString())
                .Replace("GroupName", name);
         string result = HttpRequestHelper.Request(url, data, HttpRequestHelper.Method.POST, System.Text.Encoding.UTF8);
         if (!string.IsNullOrEmpty(result))
         {
             return(JsonHelper.DeSerialize <WeChatHelper4Net.Models.RequestResultBaseModel>(result));
         }
     }
     catch (Exception Ex)
     {
         LogHelper.Save(Ex, "UpdateGroupName", LogTime.day);
         throw Ex;
     }
     return(new RequestResultBaseModel());
 }
예제 #5
0
        /// <summary>
        /// 通过code换取网页授权access_token。
        /// 如果网页授权的作用域为snsapi_base,则本步骤中获取到网页授权access_token的同时,也获取到了openid,snsapi_base式的网页授权流程即到此为止。
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static PageOAuth_AccessToken GetAccessToken(string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                throw new ArgumentException("参数值无效", nameof(code));
            }

            string url    = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", Privacy.AppId, Privacy.AppSecret, code);
            string result = HttpRequestHelper.Request(url);
            PageOAuth_AccessToken accessToken = JsonHelper.DeSerialize <PageOAuth_AccessToken>(result);

            return(accessToken);
        }
예제 #6
0
        /// <summary>
        /// 拉取用户信息(需scope为 snsapi_userinfo)
        /// </summary>
        /// <param name="access_token">网页授权接口调用凭证,注意:此access_token与基础支持的access_token不同</param>
        /// <param name="openid"></param>
        /// <param name="lang"></param>
        /// <returns></returns>
        public static UserInfo GetUserInfo(string access_token, string openid, string lang = "zh_CN")
        {
            if (string.IsNullOrWhiteSpace(access_token) || string.IsNullOrWhiteSpace(openid))
            {
                return(null);
            }

            string   url          = string.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang={2}", access_token, openid, lang);
            string   result       = HttpRequestHelper.Request(url);
            UserInfo resultEntity = JsonHelper.DeSerialize <UserInfo>(result);

            return(resultEntity);
        }
예제 #7
0
        /// <summary>
        /// 刷新access_token
        /// </summary>
        /// <param name="refresh_token"></param>
        /// <returns></returns>
        public static PageOAuth_AccessToken RefreshAccessToken(string refresh_token)
        {
            if (string.IsNullOrWhiteSpace(refresh_token))
            {
                throw new ArgumentException("参数值无效", nameof(refresh_token));
            }

            string url    = string.Format("https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={0}&grant_type=refresh_token&refresh_token={1}", Privacy.AppId, refresh_token);
            string result = HttpRequestHelper.Request(url);
            PageOAuth_AccessToken accessToken = JsonHelper.DeSerialize <PageOAuth_AccessToken>(result);

            return(accessToken);
        }
예제 #8
0
        /// <summary>
        /// 创建二维码ticket
        /// </summary>
        /// <param name="type">二维码类型,QR_SCENE为临时,QR_LIMIT_SCENE为永久</param>
        /// <param name="expire_seconds">该二维码有效时间,以秒为单位。 最大不超过604800(即7天)。</param>
        /// <param name="scene_id">场景值ID,临时二维码时为32位非0整型,永久二维码时最大值为100000(目前参数只支持1--100000)</param>
        /// <param name="scene_str">场景值ID(字符串形式的ID),字符串类型,长度限制为1到64,仅永久二维码支持此字段</param>
        /// <returns>ticket模型</returns>
        private static TicketModel getTicket(TicketType type, int expire_seconds, int scene_id, string access_token, string scene_str = "")
        {
            if (TicketType.QR_SCENE == type && expire_seconds < 1)
            {
                expire_seconds = 604800;
            }

            string      url    = Common.ApiUrl + string.Format("qrcode/create?access_token={0}", access_token);
            string      data   = string.Empty;
            TicketModel ticket = new TicketModel();

            if (type == TicketType.QR_LIMIT_SCENE)
            {
                //永久
                if (!string.IsNullOrWhiteSpace(scene_str))
                {
                    data = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"" + scene_str + "\"}}}";
                }
                else if (1 <= scene_id && scene_id <= 100000)
                {
                    data = "{\"action_name\": \"QR_LIMIT_SCENE\", \"action_info\": {\"scene\": {\"scene_id\": " + scene_id + "}}}";
                }
                else
                {
                    throw new Exception("创建二维码ticket出错!scene_id:场景值ID,临时二维码时为32位非0整型,永久二维码时最大值为100000(目前参数只支持1--100000)");
                }
            }
            else
            {
                //临时
                if (1 <= expire_seconds && expire_seconds <= 2592000)
                {
                    data = "{\"expire_seconds\": " + expire_seconds + ", \"action_name\": \"QR_SCENE\", \"action_info\": {\"scene\": {\"scene_id\": " + scene_id + "}}}";
                }
                else
                {
                    throw new Exception("创建二维码ticket出错!expire_seconds:该二维码有效时间,以秒为单位。 最大不超过604800");
                }
            }

            try
            {
                string result = HttpRequestHelper.Request(url, data, HttpRequestHelper.Method.POST, System.Text.Encoding.UTF8);
                ticket = JsonHelper.DeSerialize <TicketModel>(result);
                return(ticket);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }
예제 #9
0
        /// <summary>
        /// 拉取用户信息(需scope为 snsapi_userinfo)
        /// </summary>
        /// <param name="access_token">网页授权接口调用凭证,注意:此access_token与基础支持的access_token不同</param>
        /// <param name="openid"></param>
        /// <param name="lang"></param>
        /// <returns></returns>
        public static UserInfo GetUserInfo(string access_token, string openid, string lang = "zh_CN")
        {
            if (string.IsNullOrWhiteSpace(access_token) || string.IsNullOrWhiteSpace(openid))
            {
                return(null);
            }

            string url    = string.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang={2}", access_token, openid, lang);
            string result = HttpRequestHelper.Request(url);
            // {"openid":"od2Uu1IvIX1ypbmqnkqGTKNtHBXQ","nickname":"熊仔其人","sex":1,"language":"zh_CN","city":"海淀","province":"北京","country":"中国","headimgurl":"http:\/\/thirdwx.qlogo.cn\/mmopen\/vi_32\/Q0j4TwGTfTKOticpMHZNfGZstl5MNz9sqFwQ9bSmNbF2T2f9qlfb3mcx8pVnF7jwODBTVnNdBxekR77QBiaCLTNA\/132","privilege":[]}
            UserInfo resultEntity = JsonHelper.DeSerialize <UserInfo>(result);

            return(resultEntity);
        }
예제 #10
0
        private static JSApiTicketModel GetJSApiTicketFromWeChat(string AppId, string access_token)
        {
            if (string.IsNullOrWhiteSpace(access_token))
            {
                throw new ArgumentNullException(nameof(access_token));
            }

            string errorInfo = (string)CacheHelper.GetCache(keyState(AppId));

            if (!string.IsNullOrWhiteSpace(errorInfo) && errorInfo.Contains(Common.error))
            {
                throw new AggregateException(errorInfo + " 如果确认故障已解除,请回收应用程序池后再试");
            }

            if (GlobalFlag.Instance.wxJSApiTicket_IsBusy)
            {
                throw new ApplicationException("已经有一个请求正在进行,请稍后再试");
            }

            //获取新票据
            string url = Common.ApiUrl + string.Format("ticket/getticket?access_token={0}&type=jsapi", access_token);

            try
            {
                GlobalFlag.Instance.wxJSApiTicket_IsBusy = true;
                string           result = HttpRequestHelper.Request(url);
                JSApiTicketModel model  = JsonHelper.DeSerialize <JSApiTicketModel>(result);
                if (null != model && !string.IsNullOrWhiteSpace(model.ticket) && model.expires_in > 0)
                {
                    GlobalFlag.Instance.wxJSApiTicket_IsBusy = false;
                    return(model);
                }
                else
                {
                    CacheHelper.SetCache(keyState(AppId), string.Concat("Request API Ticket ", Common.error));
                    throw new AggregateException("获取Ticket票据失败,url=" + url + ",result=" + result);
                }
            }
            catch (Exception Ex)
            {
                GlobalFlag.Instance.wxJSApiTicket_IsBusy = false;
                LogHelper.Save(Ex);
                CacheHelper.SetCache(keyState(AppId), string.Concat("Request API Ticket ", Common.error));
                throw Ex;
            }
        }
예제 #11
0
 /// <summary>
 /// 查询所有分组
 /// </summary>
 /// <returns>GroupsModel</returns>
 public static GroupsModel GetGroup(string access_token)
 {
     try
     {
         string url    = Common.ApiUrl + string.Format("groups/get?access_token={0}", access_token);
         string result = HttpRequestHelper.Request(url, HttpRequestHelper.Method.GET);
         if (!string.IsNullOrEmpty(result))
         {
             return(JsonHelper.DeSerialize <GroupsModel>(result));
         }
     }
     catch (Exception Ex)
     {
         LogHelper.Save(Ex, "GetGroup", LogTime.day);
         throw Ex;
     }
     return(new GroupsModel());
 }
예제 #12
0
 /// <summary>
 /// 获取关注者列表,返回JSON数据包,公众号可通过本接口来获取帐号的关注者列表,关注者列表由一串OpenID(加密后的微信号,每个用户对每个公众号的OpenID是唯一的)组成。一次拉取调用最多拉取10000个关注者的OpenID,可以通过多次拉取的方式来满足需求。
 /// </summary>
 /// <param name="next_openid">第一个拉取的OPENID,不填默认从头开始拉取</param>
 /// <returns>UserListModel</returns>
 public static UserListModel GetUsers(string next_openid, string access_token)
 {
     try
     {
         string url    = Common.ApiUrl + string.Format("user/get?access_token={0}&next_openid={1}", access_token, string.IsNullOrEmpty(next_openid) ? string.Empty : next_openid);
         string result = HttpRequestHelper.Request(url, HttpRequestHelper.Method.GET);
         if (!string.IsNullOrEmpty(result))
         {
             return(JsonHelper.DeSerialize <WeChatHelper4Net.Models.UserListModel>(result));
         }
     }
     catch (Exception Ex)
     {
         LogHelper.Save(Ex, "GetUsers", LogTime.day);
         throw Ex;
     }
     return(new UserListModel());
 }
예제 #13
0
        /// <summary>
        /// 检验授权凭证(access_token)是否有效
        /// </summary>
        /// <param name="access_token">访问令牌</param>
        /// <param name="openid"></param>
        /// <returns></returns>
        public static bool CheckAccessToken(string access_token, string openid)
        {
            if (string.IsNullOrWhiteSpace(access_token) || string.IsNullOrWhiteSpace(openid))
            {
                return(false);
            }

            string url    = string.Format("https://api.weixin.qq.com/sns/auth?access_token={0}&openid={1}", access_token, openid);
            string result = HttpRequestHelper.Request(url);
            RequestResult_errmsg resultEntity = JsonHelper.DeSerialize <RequestResult_errmsg>(result);

            if (null != resultEntity && 0 == resultEntity.errcode)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #14
0
 /// <summary>
 /// 查询用户所在分组
 /// </summary>
 /// <param name="openid">用户的OpenID</param>
 /// <returns>GroupModel</returns>
 public static GroupModel GetGroupID(string openid, string access_token)
 {
     if (string.IsNullOrEmpty(openid))
     {
         return(new GroupModel());
     }
     try
     {
         string url  = Common.ApiUrl + string.Format("groups/getid?access_token={0}", access_token);
         string data = "{\"openid\":\"OpenId\"}";
         data = data.Replace("OpenId", openid);
         string result = HttpRequestHelper.Request(url, data, HttpRequestHelper.Method.POST, System.Text.Encoding.UTF8);
         if (!string.IsNullOrEmpty(result))
         {
             return(JsonHelper.DeSerialize <WeChatHelper4Net.Models.GroupModel>(result));
         }
     }
     catch (Exception Ex)
     {
         LogHelper.Save(Ex, "GetGroupID", LogTime.day);
         throw Ex;
     }
     return(new GroupModel());
 }
예제 #15
0
        /// <summary>
        /// 获取用户基本信息,返回JSON数据包
        /// </summary>
        /// <param name="openid">普通用户的标识,对当前公众号唯一</param>
        /// <returns>UserModel</returns>
        public static UserModel GetUserInfo(string openid, string access_token)
        {
            if (string.IsNullOrEmpty(openid))
            {
                return(new UserModel());
            }
            string result = string.Empty;

            try
            {
                string url = Common.ApiUrl + string.Format("user/info?access_token={0}&openid={1}&lang=zh_CN", access_token, openid);
                result = HttpRequestHelper.Request(url, HttpRequestHelper.Method.GET);
                if (!string.IsNullOrEmpty(result))
                {
                    return(JsonHelper.DeSerialize <UserModel>(StringHelper.RemoveSpecialChar(result)));
                }
            }
            catch (Exception Ex)
            {
                LogHelper.Save("【Message】:" + Ex.Message + "          【StackTrace】:" + Ex.StackTrace + "\n\r" + result, "GetUserInfo", LogType.Error, LogTime.day);
                throw Ex;
            }
            return(new UserModel());
        }
예제 #16
0
 /// <summary>
 /// 创建分组
 /// </summary>
 /// <param name="name">分组名字(30个字符以内)</param>
 /// <returns>JSON数据包</returns>
 public static GroupSubModel CreateGroup(string name, string access_token)
 {
     if (string.IsNullOrEmpty(name))
     {
         return(new GroupSubModel());
     }
     try
     {
         string url  = Common.ApiUrl + string.Format("groups/create?access_token={0}", access_token);
         string data = "{\"group\":{\"name\":\"GroupName\"}}";
         data = data.Replace("GroupName", name);
         string result = HttpRequestHelper.Request(url, data, HttpRequestHelper.Method.POST, System.Text.Encoding.UTF8);
         if (!string.IsNullOrEmpty(result))
         {
             return(JsonHelper.DeSerialize <WeChatHelper4Net.Models.GroupSubModel>(result));
         }
     }
     catch (Exception Ex)
     {
         LogHelper.Save(Ex, "CreateGroup", LogTime.day);
         throw Ex;
     }
     return(new GroupSubModel());
 }
예제 #17
0
 /// <summary>
 /// 获取永久素材(临时)
 /// </summary>
 /// <param name="ACCESS_TOKEN">访问令牌</param>
 /// <param name="MEDIA_ID"></param>
 /// <returns></returns>
 public static TempVideo GetTempVideo(string ACCESS_TOKEN, string MEDIA_ID)
 {
     if (string.IsNullOrEmpty(MEDIA_ID))
     {
         return(new TempVideo());
     }
     try
     {
         string url        = Common.ApiUrl + string.Format("media/get?access_token={0}&media_id={1}", ACCESS_TOKEN, MEDIA_ID);
         var    jsonString = "";
         string result     = HttpRequestHelper.Request(url, jsonString, HttpRequestHelper.Method.GET, System.Text.Encoding.UTF8);
         //LogHelper.Save("GetTempVideo > " + "ACCESS_TOKEN=" + ACCESS_TOKEN + ",MEDIA_ID=" + MEDIA_ID + ",result=" + result, nameof(Multimedia), LogType.Common, LogTime.day);
         if (!string.IsNullOrEmpty(result))
         {
             return(JsonHelper.DeSerialize <TempVideo>(StringHelper.RemoveSpecialChar(result)));
         }
     }
     catch (Exception Ex)
     {
         LogHelper.Save(Ex);
         throw Ex;
     }
     return(new TempVideo());
 }
예제 #18
0
        /// <summary>
        /// 删除当前使用的自定义菜单
        /// </summary>
        /// <returns></returns>
        public static string DeleteMenu(string access_token)
        {
            string url = Common.ApiUrl + string.Format("menu/delete?access_token={0}", access_token);

            return(HttpRequestHelper.Request(url));
        }
예제 #19
0
        /// <summary>
        /// 微信支付统一下单接口
        /// </summary>
        /// <param name="unifiedorder">统一下单参数</param>
        /// <param name="time">当前时间</param>
        /// <returns></returns>
        public static unifiedorderResultModel unifiedorder(unifiedorderModel unifiedorder, DateTime time)
        {
            unifiedorder.out_trade_no = !string.IsNullOrWhiteSpace(unifiedorder.out_trade_no) ? unifiedorder.out_trade_no : (Privacy.PartnerID + time.ToString("yyyyMMddHHmmss") + RandomCode.createRandomCode(3, true));
            unifiedorder.fee_type     = !string.IsNullOrWhiteSpace(unifiedorder.fee_type) ? unifiedorder.fee_type : "CNY";
            unifiedorder.time_start   = !string.IsNullOrWhiteSpace(unifiedorder.time_start) ? unifiedorder.time_start : time.ToString("yyyyMMddHHmmss");
            unifiedorder.trade_type   = !string.IsNullOrWhiteSpace(unifiedorder.trade_type) ? unifiedorder.trade_type : "JSAPI";

            unifiedorder.appid     = Privacy.AppId;
            unifiedorder.mch_id    = Privacy.PartnerID;
            unifiedorder.nonce_str = RandomCode.createRandomCode(16, true);
            unifiedorder.sign      = "";

            Dictionary <string, string> unifiedorderParams = new Dictionary <string, string>();

            unifiedorderParams.Add("appid", unifiedorder.appid);
            unifiedorderParams.Add("mch_id", unifiedorder.mch_id);
            unifiedorderParams.Add("device_info", unifiedorder.device_info);
            unifiedorderParams.Add("nonce_str", unifiedorder.nonce_str);
            unifiedorderParams.Add("sign", unifiedorder.sign);
            unifiedorderParams.Add("body", unifiedorder.body);
            unifiedorderParams.Add("detail", unifiedorder.detail);
            unifiedorderParams.Add("attach", unifiedorder.attach);
            unifiedorderParams.Add("out_trade_no", unifiedorder.out_trade_no);
            unifiedorderParams.Add("fee_type", unifiedorder.fee_type);
            unifiedorderParams.Add("total_fee", unifiedorder.total_fee.ToString());
            unifiedorderParams.Add("spbill_create_ip", unifiedorder.spbill_create_ip);
            unifiedorderParams.Add("time_start", unifiedorder.time_start);
            unifiedorderParams.Add("time_expire", unifiedorder.time_expire);
            unifiedorderParams.Add("goods_tag", unifiedorder.goods_tag);
            unifiedorderParams.Add("notify_url", unifiedorder.notify_url);
            unifiedorderParams.Add("trade_type", unifiedorder.trade_type);
            unifiedorderParams.Add("product_id", unifiedorder.product_id);
            unifiedorderParams.Add("openid", unifiedorder.openid);

            string sign    = "";
            string package = GetPackage(unifiedorderParams, out sign);

            unifiedorder.sign          = sign;
            unifiedorderParams["sign"] = sign;

            /*
             * 注:参数值用XML转义即可,CDATA标签用于说明数据不被XML解析器解析。
             */
            string unifiedorderXml = unifiedorderParams.ToXml();

            unifiedorderXml = unifiedorderXml.Replace("<unifiedorderModel>", "<xml>").Replace("</unifiedorderModel>", "</xml>");
            string resultXml = string.Empty;

            try
            {
                /*
                 * 得到最终发送的数据:
                 */
                resultXml = HttpRequestHelper.Request("https://api.mch.weixin.qq.com/pay/unifiedorder", unifiedorderXml, HttpRequestHelper.Method.POST, System.Text.Encoding.UTF8);
                resultXml = resultXml.Replace("<xml>", "<unifiedorderResultModel>").Replace("</xml>", "</unifiedorderResultModel>");
                unifiedorderResultModel result = WeChatHelper4Net.XmlHelper.DeSerialize <unifiedorderResultModel>(resultXml);
                return(result);
            }
            catch (Exception Ex)
            {
                LogHelper.Save("Pay > unifiedorder:unifiedorderXml=" + unifiedorderXml + ",resultXml=" + resultXml, "Pay", LogType.Error, LogTime.day);
                throw Ex;
            }
        }
예제 #20
0
        /// <summary>
        /// 获取自定义菜单配置
        /// </summary>
        /// <param name="access_token"></param>
        /// <returns></returns>
        public static string GetCurrentSelfMenu(string access_token)
        {
            string url = Common.ApiUrl + string.Format("get_current_selfmenu_info?access_token={0}", access_token);

            return(HttpRequestHelper.Request(url));
        }