示例#1
0
        /// <summary>
        /// 发红包xml字符串整理
        /// </summary>
        /// <param name="redpacket"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        protected static string getRedPacketXml(RedPacket redpacket, string key)
        {
            string return_string = string.Empty;
            SortedDictionary <string, string> sParams = new SortedDictionary <string, string>();

            sParams.Add("nonce_str", redpacket.nonce_str);
            sParams.Add("mch_billno", redpacket.mch_billno);
            sParams.Add("mch_id", redpacket.mch_id);
            sParams.Add("wxappid", redpacket.wxappid);
            sParams.Add("nick_name", redpacket.nick_name);
            sParams.Add("send_name", redpacket.send_name);
            sParams.Add("re_openid", redpacket.re_openid);
            sParams.Add("total_amount", redpacket.total_amount);
            sParams.Add("min_value", redpacket.min_value);
            sParams.Add("max_value", redpacket.max_value);
            sParams.Add("total_num", redpacket.total_num);
            sParams.Add("wishing", redpacket.wishing);
            sParams.Add("client_ip", redpacket.client_ip);
            sParams.Add("act_name", redpacket.act_name);
            sParams.Add("remark", redpacket.remark);
            sParams.Add("logo_imgurl", redpacket.logo_imgurl);
            sParams.Add("share_content", redpacket.share_content);
            sParams.Add("share_url", redpacket.share_url);
            sParams.Add("share_imgurl", redpacket.share_imgurl);


            redpacket.sign = getsign(sParams, key);
            sParams.Add("sign", redpacket.sign);

            #region 准备xml
            StringBuilder sbPay = new StringBuilder();
            foreach (KeyValuePair <string, string> k in sParams)
            {
                if (k.Value == "" || k.Value == null)
                {
                    continue;
                }

                if (k.Key == "attach" || k.Key == "body" || k.Key == "sign")
                {
                    sbPay.Append("<" + k.Key + "><![CDATA[" + k.Value + "]]></" + k.Key + ">");
                }
                else
                {
                    sbPay.Append("<" + k.Key + ">" + k.Value + "</" + k.Key + ">");
                }
            }
            return_string = string.Format("<xml>{0}</xml>", sbPay.ToString());
            //byte[] byteArray = Encoding.UTF8.GetBytes(return_string);
            //return_string = Encoding.GetEncoding("GBK").GetString(byteArray);
            #endregion
            return(return_string);
        }
示例#2
0
        /// <summary>
        /// 发红包
        /// </summary>
        /// <returns></returns>
        public static string Fhb(RedPacket redpacket, string key)
        {
            string returnstr = PostPage("https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack", getRedPacketXml(redpacket, key));

            return(returnstr);
        }