public object UnifiedOrder(SortedDictionary <string, string> dic)
        {
            string url = "https://api.mch.weixin.qq.com/pay/unifiedorder";

            //检测必填参数
            if (!dic.ContainsKey("out_trade_no"))
            {
                throw new Exception("缺少统一支付接口必填参数out_trade_no!");
            }
            if (!dic.ContainsKey("body"))
            {
                throw new Exception("缺少统一支付接口必填参数body!");
            }
            if (!dic.ContainsKey("total_fee"))
            {
                throw new Exception("缺少统一支付接口必填参数total_fee!");
            }
            if (!dic.ContainsKey("trade_type"))
            {
                throw new Exception("缺少统一支付接口必填参数trade_type!");
            }

            //关联参数
            if (dic["trade_type"] == "JSAPI" && !dic.ContainsKey("openid"))
            {
                throw new Exception("统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!");
            }
            if (dic["trade_type"] == "NATIVE" && !dic.ContainsKey("product_id"))
            {
                throw new Exception("统一支付接口中,缺少必填参数product_id!trade_type为JSAPI时,product_id为必填参数!");
            }
            if (!dic.ContainsKey("notify_url"))
            {
                throw new Exception("异步通知Url未设置");
            }

            //添加公共部分参数
            dic.Add("appid", _commonService.AppId);
            dic.Add("mch_id", Mchid);
            dic.Add("spbill_create_ip", "127.0.0.1");
            dic.Add("nonce_str", _helper.GenerateNonceStr());

            dic.Add("sign", MakeSign(dic));
            var         xml      = _helper.ConvertToXml(dic);
            var         response = _helper.SendPost(url, xml, null);
            XmlDocument xmlDoc   = new XmlDocument();

            xmlDoc.LoadXml(response);
            return(xmlDoc);
        }
Exemple #2
0
        /// <summary>
        /// 批量获取用户基本信息(最多支持一次拉取100条)
        /// </summary>
        /// <param name="openIds"></param>
        /// <param name="lang"></param>
        /// <returns></returns>
        public UserInfoList GetUsersInfo(List <string> openIds, string lang = "zh-CN")
        {
            var users        = openIds.Select(o => new { openid = o, lang = lang }).ToArray();
            var postData     = new { user_list = users };
            var postDataJson = JsonConvert.SerializeObject(postData);

            var response = _helper.SendPost(string.Format("https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token={0}", AccessToken), postDataJson, null);
            var result   = JsonConvert.DeserializeObject <UserInfoList>(response);

            if (result.errcode != 0)
            {
                _log.Error("批量获取用户基本信息出错,错误代码{0},错误信息:{1}", result.errcode, result.errmsg);
                return(null);
            }
            else
            {
                return(result);
            }
        }
        public bool CreateMenu(NormalMenu model, out string msg)
        {
            msg = "";
            var jsonSetting = new JsonSerializerSettings
            {
                ContractResolver  = new LowercaseResolver(),
                NullValueHandling = NullValueHandling.Ignore
            };

            var result =
                _wcHelper.SendPost(
                    "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + _wcCommonService.AccessToken,
                    JsonConvert.SerializeObject(model, jsonSetting), "application/json; encoding=utf-8");
            var resultModel = JsonConvert.DeserializeObject <MessageResultModel>(result);

            if (resultModel.Errcode != 0)
            {
                msg = string.Format("创建自定义菜单出错,错误代码{0},错误信息:{1}", resultModel.Errcode, resultModel.ErrMsg);
                _log.Error(msg);
                return(false);
            }
            return(true);
        }