Esempio n. 1
0
        /// <summary>
        /// 统一下单接口
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        public void CreateOrders(CreateOrder request, CreateOrderResponse response)
        {
            DateTime dt         = DateTime.Now;
            string   timeStart  = string.Format("{0:yyyyMMddHHmmss}", dt);
            string   timeExpire = string.Format("{0:yyyyMMddHHmmss}", dt.AddSeconds(300));
            SortedDictionary <string, string> ht = new SortedDictionary <string, string>
            {
                { "appid", ConfigurationManager.AppSettings["APPID"] },
                { "mch_id", ConfigurationManager.AppSettings["MCHID"] },
                { "device_info", "WEB" },
                { "nonce_str", RandomHelper.GenerateString(32) },
                { "sign_type", "MD5" },
                { "body", request.Body },
                { "detail", request.Detail },
                { "attach", request.Attach },
                { "out_trade_no", request.OutTradeNo },
                { "fee_type", "CNY" },
                { "total_fee", "" + request.TotalFee },
                { "spbill_create_ip", request.SpbillCreateIp },
                { "time_start", timeStart },
                { "time_expire", timeExpire },
                { "goods_tag", request.GoodsTag },
                { "notify_url", ConfigurationManager.AppSettings["NOTIFYURL"] },
                { "trade_type", "JSAPI" },
                { "openid", request.Openid },
                { "product_id", request.ProductId }
            };

            if (string.IsNullOrEmpty(request.LimitPay))
            {
                if (request.LimitPay == "no_credit")
                {
                    ht.Add("limit_pay", "no_credit");
                }
            }

            string sign = Md5Helper.UserMd5(WxPayHelper.CreateSign(ht));

            ht.Add("sign", sign);
            string    postXml  = WxPayHelper.CreateXmlRequest(ht);
            string    wxResult = HttpRequestUtil.HttpPost(UrlUnifiedorder, postXml);
            Hashtable htt      = XmlAndJsonToHash.XmlToHashTable(wxResult);

            wxResult = JsonHelper.ToJson(htt);
            CoResponse tr = JsonHelper.Deserialize <CoResponse>(wxResult);

            response.ResponseStatus.ErrorCode = tr.return_code;
            response.ResponseStatus.Message   = tr.return_msg;
            if (tr.return_code == "SUCCESS" && tr.result_code == "SUCCESS")
            {
                response.PrepayId = tr.prepay_id;
            }
            else
            {
                response.ResponseStatus.ErrorCode = tr.err_code;
                response.ResponseStatus.Message   = tr.err_code_des;
            }
        }
Esempio n. 2
0
        private void Handle(string postData, WeChatRequest model)
        {
            Hashtable hh = XmlAndJsonToHash.XmlToHashTable(postData);

            Logger.Info(hh.ToString());
            // 消息MsgId
            String msgId = hh["MsgId"].ToString();
            // 发送方帐号(open_id)
            String fromUserName = hh["FromUserName"].ToString();
            // 公众帐号
            String toUserName = hh["ToUserName"].ToString();
            // 消息类型
            String msgType = hh["MsgType"].ToString();
            // 消息内容
            String content = hh["Content"].ToString();
            // 发送时间
            String createTime = hh["CreateTime"].ToString();
            String eventType;
            String eventKey;

            if (Constants.ReqMessageTypeEvent.Equals(msgType))
            {
                eventType = hh["EventKey"].ToString();
                if (Constants.EventTypeClick.Equals(eventType))
                {
                    // 事件KEY值,与创建自定义菜单时指定的KEY值对应
                    eventKey = hh["EventKey"].ToString();
                    content  = "click_" + eventKey;
                }
                else if (Constants.EventTypeTemplatesendjobfinish.Equals(eventType))
                {
                    eventKey = hh["EventKey"].ToString();
                    content  = "click_" + eventKey;
                }
            }
        }