Exemple #1
0
        /// <summary>
        ///据订单状态/创建时间获取订单详情
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="status">订单状态(不带该字段-全部状态, 2-待发货, 3-已发货, 5-已完成, 8-维权中, )</param>
        /// <param name="begintime">订单创建时间起始时间(不带该字段则不按照时间做筛选)</param>
        /// <param name="endtime">订单创建时间终止时间(不带该字段则不按照时间做筛选)</param>
        /// <returns>订单详情,参见官方文档</returns>
        public static string GetByFilter(string access_token, int status, long begintime = 0, long endtime = 0)
        {
            var content = new StringBuilder();

            content.Append("{")
            .Append('"' + "status" + '"' + ": " + status);
            if (begintime > 0 || endtime > 0)
            {
                content.Append(",");
                if (begintime <= 0)
                {
                    begintime = DateTime.MinValue.ToTimestamp();
                }
                if (endtime <= 0)
                {
                    endtime = DateTime.Now.ToTimestamp();
                }
                content.Append('"' + "begintime" + '"' + ": " + begintime).Append(",");
                if (endtime <= 0)
                {
                    endtime = DateTime.Now.ToTimestamp();
                }
                content.Append('"' + "endtime" + '"' + ": " + endtime);
            }
            content.Append("}");
            var result = HttpTo.Post(string.Format("https://api.weixin.qq.com/merchant/order/getbyfilter?access_token={0}", access_token),
                                     content.ToString());

            return(result);
        }
Exemple #2
0
            /// <summary>
            /// 公共API => 申请退款
            /// 需要双向证书
            /// http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_4
            ///应用场景
            ///当交易发生之后一段时间内,由于买家或者卖家的原因需要退款时,卖家可以通过退款接口将支付款退还给买家,微信支付将在收到退款请求并且验证成功之后,按照退款规则将支付款按原路退到买家帐号上。
            ///注意:
            ///1.交易时间超过半年的订单无法提交退款;
            ///2.微信支付退款支持单笔交易分多次退款,多次退款需要提交原支付订单的商户订单号和设置不同的退款单号。一笔退款失败后重新提交,要采用原来的退款单号。总退款金额不能超过用户实际支付金额。
            ///3.接口提交成功后,还需要在微信商户后台由商户管理员审核退款
            /// </summary>
            /// <param name="appid">(必填) String(32) 微信分配的公众账号ID</param>
            /// <param name="mch_id">(必填) String(32) 微信支付分配的商户号</param>
            /// <param name="device_info"> String(32) 微信支付分配的终端设备号,商户自定义</param>
            /// <param name="nonce_str">(必填) 随机字符串 随机字符串,不长于32位。</param>
            /// <param name="transaction_id">String(32) 微信订单号 微信的订单号,优先使用 </param>
            /// <param name="out_trade_no">(transaction_id为空时必填) String(32) 商户订单号 transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no </param>
            /// <param name="out_refund_no">(必填) String(32) 商户退款单号 商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔 </param>
            /// <param name="total_fee">(必填) int 总金额 订单总金额,单位为分,只能为整数。 </param>
            /// <param name="refund_fee">(必填) int  退款金额 退款总金额,订单总金额,单位为分,只能为整数</param>
            /// <param name="refund_fee_type">String(8) 货币种类 符合ISO 4217标准的三位字母代码,默认人民币:CNY</param>
            /// <param name="op_user_id">(必填) String(32) 操作员 操作员帐号, 默认为商户号mch_id </param>
            /// <param name="partnerKey">API密钥</param>
            /// <returns> 参见:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_4 </returns>
            public static string Refund(string appid, string mch_id, string device_info, string nonce_str,
                                        string transaction_id, string out_trade_no, string out_refund_no,
                                        int total_fee, int refund_fee, string refund_fee_type, string op_user_id,
                                        string partnerKey)
            {
                var stringADict = new Dictionary <string, string>
                {
                    { "appid", appid },
                    { "mch_id", mch_id },
                    { "device_info", device_info },
                    { "nonce_str", nonce_str },
                    { "transaction_id", transaction_id },
                    { "out_trade_no", out_trade_no },
                    { "out_refund_no", out_refund_no },
                    { "total_fee", total_fee.ToString() },
                    { "refund_fee", refund_fee.ToString() },
                    { "refund_fee_type", refund_fee_type },
                    { "op_user_id", op_user_id }
                };

                var sign     = PayUtil.Sign(stringADict, partnerKey);//生成签名字符串
                var postdata = PayUtil.GeneralPostdata(stringADict, sign);
                var url      = "https://api.mch.weixin.qq.com/secapi/pay/refund";

                var result = HttpTo.Post(url, postdata);

                return(result);
            }
Exemple #3
0
        /// <summary>
        /// 提交被扫支付API
        /// http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=5_5
        /// 1.应用场景:收银员使用扫码设备读取微信用户刷卡授权码以后,二维码或条码信息传送至商户收银台,由商户收银台或者商户后台调用该接口发起支付。
        ///是否需要证书:不需要。
        /// <param name="appid">(必填) String(32) 微信分配的公众账号ID</param>
        /// <param name="mch_id">(必填) String(32) 微信支付分配的商户号</param>
        /// <param name="device_info"> String(32) 微信支付分配的终端设备号,商户自定义</param>
        /// <param name="nonce_str">(必填) String(32) 随机字符串,不长于32位</param>
        /// <param name="body">(必填) String(32) 商品描述 商品或支付单简要描</param>
        /// <param name="detail"> String(8192) 商品详情  商品名称明细列表</param>
        /// <param name="attach"> String(127) 附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据</param>
        /// <param name="out_trade_no">(必填) String(32) 商家订单ID,32个字符内、可包含字母, 其他说明见第4.2节商户订单号:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=4_2 </param>
        /// <param name="fee_type">符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见第4.2节货币类型: http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=4_2 </param>
        /// <param name="total_fee">(必填) Int 订单总金额,只能为整数,详见第4.2节支付金额:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=4_2 </param>
        /// <param name="spbill_create_ip">(必填) String(32)终端IP APP和网页支付提交用户端IP,Native支付填调用微信支付API的机器IP。</param>
        /// <param name="time_start">String(14) 订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。</param>
        /// <param name="time_expire">String(14) 订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。</param>
        /// <param name="goods_tag">String(32) 商品标记,代金券或立减优惠功能的参数,说明详见第10节代金券或立减优惠:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=10_1 </param>
        /// <param name="auth_code">String(128) 授权码 扫码支付授权码,设备读取用户微信中的条码或者二维码信息 </param>
        /// <param name="partnerKey">API密钥</param>
        /// </summary>
        /// <returns>返回json字符串,格式参见:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=5_5 </returns>
        public static string MicroPay(string appid, string mch_id, string device_info,
                                      string nonce_str, string body, string detail, string attach,
                                      string out_trade_no, string fee_type, int total_fee, string spbill_create_ip,
                                      string time_start, string time_expire, string goods_tag,
                                      string auth_code,
                                      string partnerKey)
        {
            var stringADict = new Dictionary <string, string>
            {
                { "appid", appid },
                { "mch_id", mch_id },
                { "device_info", device_info },
                { "nonce_str", nonce_str },
                { "body", body },
                { "attach", attach },
                { "out_trade_no", out_trade_no },
                { "fee_type", fee_type },
                { "total_fee", total_fee.ToString() },
                { "spbill_create_ip", spbill_create_ip },
                { "time_start", time_start },
                { "time_expire", time_expire },
                { "goods_tag", goods_tag },
                { "auth_code", auth_code }
            };
            var sign     = PayUtil.Sign(stringADict, partnerKey);//生成签名字符串
            var postdata = PayUtil.GeneralPostdata(stringADict, sign);
            var url      = "https://api.mch.weixin.qq.com/pay/micropay";

            var result = HttpTo.Post(url, postdata);

            return(result);
        }
Exemple #4
0
        /// <summary>
        /// 设置测试用户白名单
        /// 由于卡券有审核要求,为方便公众号调试,可以设置一些测试帐号,这些帐号可领取未通过审核的卡券,体验整个流程。
        /// 注:同时支持“openid”、“username”两种字段设置白名单,总数上限为10个。
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="testwhitelist">
        /// {
        ///"openid":[ //测试的openid列表
        ///"o1Pj9jmZvwSyyyyyyBa4aULW2mA",
        ///"o1Pj9jmZvxxxxxxxxxULW2mA"
        ///],
        ///"username":[ //测试的微信号列表
        ///"afdvvf",
        ///"abcd"
        ///]
        ///}
        /// </param>
        /// <returns></returns>
        public static string Set(string access_token, object testwhitelist)
        {
            var url    = string.Format("https://api.weixin.qq.com/card/testwhitelist/set?access_token={0}", access_token);
            var result = HttpTo.Post(url, testwhitelist.ToJson());

            return(result);
        }
Exemple #5
0
        /// <summary>
        /// 批量导入门店信息
        /// 接口说明
        ///支持商户调用该接口批量导入/新建门店信息,获取门店ID。
        ///注:通过该接口导入的门店信息将进入门店审核流程,审核期间可正常使用。若导入的
        ///门店信息未通过审核,则会被剔除出门店列表。
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="location_list">门店列表
        /// 数据示意:
        /// {"location_list":[
        ///{
        ///"business_name":"麦当劳",
        ///"branch_name":"赤岗店",
        ///"province":"广东省",
        ///"city":"广州市",
        ///"district":"海珠区",
        ///"address":"中国广东省广州市海珠区艺苑路11号",
        ///"telephone":"020-89772059",
        ///"category":"房产小区",
        ///"longitude":"115.32375",
        ///"latitude":"25.097486"
        ///},
        ///{
        ///"business_name":"麦当劳",
        ///"branch_name":"珠江店",
        ///"province":"广东省",
        ///"city":"广州市",
        ///"district":"海珠区",
        ///"address":"中国广东省广州市海珠区艺苑路12号",
        ///"telephone":"020-89772059",
        ///"category":"房产小区",
        ///"longitude":"113.32375",
        ///"latitude":"23.097486"
        ///}]}</param>
        /// <returns>
        /// {
        /// "errcode":0,
        /// "errmsg":"ok",
        /// "location_id_list":[271262077,-1]
        ///}
        ///其中location_id_list中的 -1 表示失败
        /// </returns>
        public static string BatchAdd(string access_token, object location_list)
        {
            var url    = string.Format("https://api.weixin.qq.com/card/location/batchadd?access_token={0}", access_token);
            var result = HttpTo.Post(url, location_list.ToJson());

            return(result);
        }
Exemple #6
0
        /// <summary>
        /// 公共API => 测速上报
        /// 不需要证书
        /// http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_8
        ///应用场景
        ///商户在调用微信支付提供的相关接口时,会得到微信支付返回的相关信息以及获得整个接口的响应时间。为提高整体的服务水平,
        ///协助商户一起提高服务质量,微信支付提供了相关接口调用耗时和返回信息的主动上报接口,微信支付可以根据商户侧上报的数据进一步优化网络部署,完善服务监控,和商户更好的协作为用户提供更好的业务体验。
        /// </summary>
        /// <param name="appid">(必填) String(32) 微信分配的公众账号ID</param>
        /// <param name="mch_id">(必填) String(32) 微信支付分配的商户号</param>
        /// <param name="device_info"> String(32) 微信支付分配的终端设备号,商户自定义</param>
        /// <param name="nonce_str">(必填) 随机字符串 随机字符串,不长于32位。</param>
        /// <param name="interface_url">String(127) 接口URL  上报对应的接口的完整URL,类似:
        ///https://api.mch.weixin.qq.com/pay/unifiedorder
        ///对于被扫支付,为更好的和商户共同分析一次业务行为的整体耗时情况,对于两种接入模式,请都在门店侧对一次被扫行为进行一次单独的整体上报,上报URL指定为:
        ///https://api.mch.weixin.qq.com/pay/micropay/total
        ///关于两种接入模式具体可参考本文档章节:被扫支付商户接入模式
        ///其它接口调用仍然按照调用一次,上报一次来进行。
        /// </param>
        /// <param name="execute_time_">Int  接口耗时   接口耗时情况,单位为毫秒 </param>
        /// <param name="return_code">String(16)  返回状态码   接口耗时情况,单位为毫秒 </param>
        /// <param name="return_msg">String(128)  返回信息    返回信息,如非空,为错误原因 :签名失败; 参数格式校验错误 </param>
        /// <param name="result_code">String(16)  业务结果    SUCCESS/FAIL </param>
        /// <param name="err_code">String(32)  错误代码   </param>
        /// <param name="err_code_des">String(128)  错误代码描述</param>
        /// <param name="out_trade_no">String(32)  商户订单号 商户系统内部的订单号,商户可以在上报时提供相关商户订单号方便微信支付更好的提高服务质量。 </param>
        /// <param name="user_ip">String(16)  访问接口IP   发起接口调用时的机器IP  </param>
        /// <param name="time">String(14)  商户上报时间 系统时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。 其他详见第4.2节时间规则:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=4_2  </param>
        /// <param name="partnerKey">API密钥</param>
        /// <returns> 参见:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_8 </returns>
        public static string RefundQuery(string appid, string mch_id, string device_info, string nonce_str,
                                         string interface_url, string execute_time_,
                                         string return_code, string return_msg, string result_code, string err_code,
                                         string err_code_des, string out_trade_no, string user_ip, string time,
                                         string partnerKey)
        {
            var stringADict = new Dictionary <string, string>
            {
                { "appid", appid },
                { "mch_id", mch_id },
                { "device_info", device_info },
                { "nonce_str", nonce_str },
                { "interface_url", interface_url },
                { "execute_time_", execute_time_ },
                { "return_code", return_code },
                { "return_msg", return_msg },
                { "result_code", result_code },
                { "err_code", err_code },
                { "err_code_des", err_code_des },
                { "out_trade_no", out_trade_no },
                { "user_ip", user_ip },
                { "time", time }
            };

            var sign     = PayUtil.Sign(stringADict, partnerKey);//生成签名字符串
            var postdata = PayUtil.GeneralPostdata(stringADict, sign);
            var url      = "https://api.mch.weixin.qq.com/pay/refundquery";

            var result = HttpTo.Post(url, postdata);

            return(result);
        }
Exemple #7
0
            /// <summary>
            /// 更新电影票
            /// 领取电影票后通过调用“更新电影票”接口update电影信息及用户选座信息。
            /// </summary>
            /// <param name="access_token"></param>
            /// <param name="tickect">
            /// {
            ///"code":"198374613512",
            ///"card_id":"p1Pj9jr90_SQRaVqYI239Ka1erkI",
            ///"passenger_name":"乘客姓名",//乘客姓名,上限为15个汉字。
            ///"class":"舱等",//舱等,如头等舱等,上限为5个汉字。
            ///"seat":"座位号",//乘客座位号。
            ///"etkt_bnr":"电子客票号",//电子客票号,上限为14个数字
            ///"qrcode_data":"二维码数据",//乘客用于值机的二维码字符串,微信会通过此数据为用户生成值机用的二维码。
            ///"is_cancel ":false//填写true或false。true代表取消,如填写true上述字段(如calss等)均不做判断,机票返回未值机状态,乘客可重新值机。默认填写false
            ///   }
            /// </param>
            /// <returns>
            /// {
            ///"errcode":0,
            ///"errmsg":"ok"
            ///}
            ///</returns>
            public static string CheckIn(string access_token, object tickect)
            {
                var url    = string.Format("https://api.weixin.qq.com/card/boardingpass/checkin?access_token={0}", access_token);
                var result = HttpTo.Post(url, tickect.ToJson());

                return(result);
            }
Exemple #8
0
        /// <summary>
        /// 创建卡券
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="card">
        /// 数据示意:
        /// {"card":{
        /// "card_type":"GROUPON",
        /// "groupon":{
        /// "base_info":{
        /// "logo_url":
        /// "http:\/\/www.supadmin.cn\/uploads\/allimg\/120216\/1_120216214725_1.jpg",
        /// "brand_name":"海底捞",
        /// "code_type":"CODE_TYPE_TEXT",
        /// "title":"132元双人火锅套餐",
        /// "sub_title":"",
        /// "color":"Color010",
        /// "notice":"使用时向服务员出示此券",
        /// "service_phone":"020-88888888",
        /// "description":"不可与其他优惠同享\n如需团购券发票,请在消费时向商户提出\n店内均可
        ///                使用,仅限堂食\n餐前不可打包,餐后未吃完,可打包\n本团购券不限人数,建议2人使用,超过建议人
        ///                数须另收酱料费5元/位\n本单谢绝自带酒水饮料",
        /// "date_info":{
        /// "type":1,
        /// "begin_timestamp":1397577600,
        /// "end_timestamp":1422724261
        /// },
        /// "sku":{
        /// "quantity":50000000
        /// },
        ///  "get_limit":3,
        /// "use_custom_code":false,
        /// "bind_openid":false,
        /// "can_share":true,
        /// "can_give_friend":true,
        /// "location_id_list": [123,12321,345345],
        /// "url_name_type":"URL_NAME_TYPE_RESERVATION",
        /// "custom_url":"http://www.qq.com",
        /// "source":"大众点评"
        ///   },
        /// "deal_detail":"以下锅底2选1(有菌王锅、麻辣锅、大骨锅、番茄锅、清补凉锅、酸菜鱼锅可
        /// 选):\n大锅1份12元\n小锅2份16元\n以下菜品2选1\n特级肥牛1份30元\n洞庭鮰鱼卷1份
        /// 20元\n其他\n鲜菇猪肉滑1份18元\n金针菇1份16元\n黑木耳1份9元\n娃娃菜1份8元\n冬
        /// 瓜1份6元\n火锅面2个6元\n欢乐畅饮2位12元\n自助酱料2位10元"}
        /// }
        /// }
        /// 具体参数意义,请参见官方文档。
        /// </param>
        /// <returns>
        /// {
        ///"errcode":0,
        ///"errmsg":"ok",
        ///"card_id":"p1Pj9jr90_SQRaVqYI239Ka1erkI"
        /// }</returns>
        public static string Create(string access_token, object card)
        {
            var url    = string.Format("https://api.weixin.qq.com/card/create?access_token={0}", access_token);
            var result = HttpTo.Post(url, card.ToJson());

            return(result);
        }
Exemple #9
0
        /// <summary>
        /// 创建二维码
        /// 创建卡券后,商户可通过接口生成一张卡券二维码供用户扫码后添加卡券到卡包。
        ///自定义code的卡券调用接口时,post数据中需指定code,非自定义code不需指定,
        ///指定openid同理。指定后的二维码只能被扫描领取一次。
        ///
        /// 获取二维码ticket后,开发者可用ticket换取二维码图片详情
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="action">
        /// 数据示意:
        /// {
        /// "action_name":"QR_CARD",
        /// "action_info":{
        /// "card":{
        /// "card_id":"pFS7Fjg8kV1IdDz01r4SQwMkuCKc",
        /// "code":"198374613512",
        /// "openid":"oFS7Fjl0WsZ9AMZqrI80nbIq8xrA",
        /// "expire_seconds":"1800",
        /// "is_unique_code":false,
        /// "outer_id": 1
        /// }
        /// }
        /// }</param>
        /// <returns>二维码图片地址</returns>
        public static string Create(string access_token, object action)
        {
            var url    = string.Format("https://api.weixin.qq.com/card/qrcode/create?access_token={0}", access_token);
            var result = HttpTo.Post(url, action.ToJson());
            var ticket = result.ToJObject()["ticket"].ToString();

            return(string.Format("https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket={0}", ticket));
        }
Exemple #10
0
        /// <summary>
        /// 更新电影票
        /// 领取电影票后通过调用“更新电影票”接口update电影信息及用户选座信息。
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="tickect">
        /// {
        ///"code": "277217129962",
        ///"card_id":"p1Pj9jr90_SQRaVqYI239Ka1erkI",
        ///"ticket_class":"4D",
        ///"show_time":1408493192,
        ///"duration":120,
        ///"screening_room":"5号影厅",
        ///"seat_number":["5排14号", "5排15号"]
        ///   }
        /// </param>
        /// <returns>
        /// {
        ///"errcode":0,
        ///"errmsg":"ok"
        ///}
        ///</returns>
        public static string UpdateUser(string access_token, object tickect)
        {
            var url = string.Format("https://api.weixin.qq.com/card/movieticket/updateuser?access_token={0}", access_token);

            var result = HttpTo.Post(url, tickect.ToJson());

            return(result);
        }
Exemple #11
0
        /// <summary>
        /// 激活/绑定会员卡支持以下两种方式:
        ///1.用户点击卡券内“bind_old_card_url”、“activate_url”跳转商户自定义的H5页面,填写相关身份认证信息后,商户调用接口,完成激活/绑定。
        ///2.商户已知用户身份或无需进行绑定等操作,用户领取会员卡后,商户后台即时调用“激活/绑定会员卡”接口update会员卡编号及积分信息。
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="memeber_card">
        /// {
        ///"init_bonus": 100,
        ///"init_balance": 200,
        ///"membership_number": "AAA00000001",
        ///"code":"12312313",
        ///"card_id":"xxxx_card_id"
        ///}
        ///或
        ///{
        ///"bonus": “www.xxxx.com”,
        ///"balance":“www.xxxx.com”,
        ///"membership_number": "AAA00000001",
        ///"code":"12312313",
        ///"card_id":"xxxx_card_id"
        ///}
        /// </param>
        /// <returns>
        /// {
        ///"errcode":0,
        ///"errmsg":"ok"
        ///}
        ///</returns>
        public static string Activate(string access_token, object memeber_card)
        {
            var url = string.Format("https://api.weixin.qq.com/card/membercard/activate?access_token={0}", access_token);

            var result = HttpTo.Post(url, memeber_card.ToJson());

            return(result);
        }
Exemple #12
0
        /// <summary>
        /// 删除分组
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="group_id">分组ID</param>
        /// <returns>
        /// {
        /// "errcode":0,
        /// "errmsg":"success"
        /// }
        /// </returns>
        public static string Del(string access_token, int group_id)
        {
            var content = new StringBuilder();

            content.Append("{")
            .Append('"' + "group_id" + '"' + ": " + group_id)
            .Append("}");
            var result = HttpTo.Post(string.Format("https://api.weixin.qq.com/merchant/group/del?access_token={0}", access_token), content.ToString());

            return(result);
        }
Exemple #13
0
        /// <summary>
        /// 修改分组属性
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="group_id"></param>
        /// <param name="group_name"></param>
        /// <returns>
        /// {
        ///  "errcode":0,
        /// "errmsg":"success"
        /// }
        /// </returns>
        public static string PropertyMod(string access_token, int group_id, string group_name)
        {
            var content = new StringBuilder();

            content.Append("{")
            .Append('"' + "group_id" + '"' + ": " + group_id).Append(",")
            .Append('"' + "group_name" + '"' + ": " + '"' + group_name + '"')
            .Append("}");
            var result = HttpTo.Post(string.Format("https://api.weixin.qq.com/merchant/group/propertymod?access_token={0}", access_token), content.ToString());

            return(result);
        }
Exemple #14
0
        /// <summary>
        /// 删除卡券
        /// 删除卡券接口允许商户删除任意一类卡券。删除卡券后,该卡券对应已生成的领取用二维码、添加到卡包JSAPI均会失效。
        /// 注意:如用户在商家删除卡券前已领取一张或多张该卡券依旧有效。即删除卡券不能删除已被用户领取,保存在微信客户端中的卡券。
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="card_id">卡券ID</param>
        /// <returns>{
        ///"errcode":0,
        ///"errmsg":"ok"
        ///}</returns>
        public static string Delete(string access_token, string card_id)
        {
            var url = string.Format("https://api.weixin.qq.com/card/delete?access_token={0}", access_token);
            var sb  = new StringBuilder();

            sb.Append("{")
            .Append('"' + "card_id" + '"' + ":").Append(card_id)
            .Append("}");
            var result = HttpTo.Post(url, sb.ToString());

            return(result);
        }
Exemple #15
0
        /// <summary>
        /// 修改邮费模板
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="template_id">邮费模板ID</param>
        /// <param name="delivery_template">邮费模板信息(字段说明详见增加邮费模板)</param>
        /// <returns>
        /// {
        /// "errcode": 0,
        ///"errmsg": "success"
        ///}
        /// </returns>
        public static string Del(string access_token, int template_id, object delivery_template)
        {
            var content = new StringBuilder();

            content.Append("{")
            .Append('"' + "template_id" + '"' + ": " + template_id).Append(",")
            .Append('"' + "delivery_template" + '"' + ": ").Append(delivery_template.ToJson())
            .Append("}");
            var result = HttpTo.Post(string.Format("https://api.weixin.qq.com/merchant/express/del?access_token={0}", access_token), content.ToString());

            return(result);
        }
Exemple #16
0
        /// <summary>
        /// 根据货架ID获取货架信息
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="shelf_id">货架ID</param>
        /// <returns>
        /// {
        /// "errcode": 0,
        /// "errmsg": "success",
        /// "shelf_info": {
        ///     "module_infos": [...]
        /// },
        /// "shelf_banner": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2ibp2DgDXiaic6WdflMpNdInS8qUia2BztlPu1gPlCDLZXEjia2qBdjoLiaCGUno9zbs1UyoqnaTJJGeEew/0",
        /// "shelf_name": "新建货架",
        /// "shelf_id": 97
        /// }
        /// </returns>
        public static string GetById(string access_token, int shelf_id)
        {
            var content = new StringBuilder();

            content.Append("{")
            .Append('"' + "shelf_id" + '"' + ": " + shelf_id)
            .Append("}");
            var result = HttpTo.Post(string.Format("https://api.weixin.qq.com/merchant/shelf/getbyid?access_token={0}", access_token),
                                     content.ToString());

            return(result);
        }
Exemple #17
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="product_id"></param>
        /// <returns>
        /// 商品详细信息,
        /// 具体请参见官方文档</returns>
        public static string Get(string access_token, string product_id)
        {
            var content = new StringBuilder();

            content.Append("{")
            .Append('"' + "product_id" + '"' + ": " + '"' + product_id + '"')
            .Append("}");
            var result = HttpTo.Post(string.Format("https://api.weixin.qq.com/merchant/get?access_token={0}", access_token),
                                     content.ToString());

            return(result);
        }
Exemple #18
0
            /// <summary>
            /// 获取指定分类的所有属性
            /// </summary>
            /// <param name="access_token"></param>
            /// <param name="cate_id"></param>
            /// <returns></returns>
            public static string GetProperty(string access_token, string cate_id)
            {
                var content = new StringBuilder();

                content.Append("{")
                .Append('"' + "cate_id" + '"' + ": " + cate_id)
                .Append("}");
                var result = HttpTo.Post(string.Format("https://api.weixin.qq.com/merchant/category/getproperty?access_token={0}", access_token),
                                         content.ToString());

                return(result);
            }
Exemple #19
0
        /// <summary>
        /// 修改分组商品
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="group_id"></param>
        /// <param name="product">分组商品信息, 数据示例:
        /// [
        /// {
        ///     "product_id": "pDF3iY-CgqlAL3k8Ilz-6sj0UYpk",
        ///     "mod_action": 1
        /// },
        /// {
        ///     "product_id": "pDF3iY-RewlAL3k8Ilz-6sjsepp9",
        ///     "mod_action": 0
        /// },
        /// ]
        /// </param>
        /// <returns>
        /// {
        ///  "errcode":0,
        /// "errmsg":"success"
        /// }
        /// </returns>
        public static string ProductMod(string access_token, int group_id, object product)
        {
            var content = new StringBuilder();

            content.Append("{")
            .Append('"' + "group_id" + '"' + ": " + group_id).Append(",")
            .Append('"' + "product" + '"' + ": ").Append(product.ToJson())
            .Append("}");
            var result = HttpTo.Post(string.Format("https://api.weixin.qq.com/merchant/group/productmod?access_token={0}", access_token), content.ToString());

            return(result);
        }
Exemple #20
0
            /// <summary>
            /// code解码接口
            /// code解码接口支持两种场景:
            ///1.商家获取choos_card_info后,将card_id和encrypt_code字段通过解码接口,获取真实code。
            ///2.卡券内跳转外链的签名中会对code进行加密处理,通过调用解码接口获取真实code。
            /// </summary>
            /// <param name="access_token"></param>
            /// <param name="encrypt_code">通过choose_card_info获取的加密字符串</param>
            /// <returns>
            /// {
            ///"errcode":0,
            ///"errmsg":"ok",
            ///"code":"751234212312"
            ///}
            /// </returns>
            public static string Decrypt(string access_token, string encrypt_code)
            {
                var url = string.Format("https://api.weixin.qq.com/card/code/decrypt?access_token={0}", access_token);

                var sb = new StringBuilder();

                sb.Append("{")
                .Append('"' + "encrypt_code" + '"' + ":").Append(encrypt_code)
                .Append("}");
                var result = HttpTo.Post(url, sb.ToString());

                return(result);
            }
Exemple #21
0
        /// <summary>
        /// 批量查询卡列表
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="offset">查询卡列表的起始偏移量,从0开始,即offset:5是指从从列表里的第六个开始读取。</param>
        /// <param name="count">需要查询的卡片的数量(数量最大50)</param>
        /// <returns>{
        /// "errcode":0,
        /// "errmsg":"ok",
        /// "card_id_list":["ph_gmt7cUVrlRk8swPwx7aDyF-pg"],
        /// "total_num":1
        /// }</returns>
        public static string BatchGet(string access_token, int offset, int count)
        {
            var url = string.Format("https://api.weixin.qq.com/card/batchget?access_token={0}", access_token);
            var sb  = new StringBuilder();

            sb.Append("{")
            .Append('"' + "offset" + '"' + ":").Append(offset)
            .Append('"' + "count" + '"' + ":").Append(count)
            .Append("}");
            var result = HttpTo.Post(url, sb.ToString());

            return(result);
        }
Exemple #22
0
        /// <summary>
        /// 减少库存
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="product_id">商品ID</param>
        /// <param name="sku_info">sku信息,格式"id1:vid1;id2:vid2"</param>
        /// <param name="quantity">减少的库存数量</param>
        /// <returns>
        /// {
        /// "errcode":0,
        /// "errmsg":"success"
        /// }
        /// </returns>
        public static string Reduce(string access_token, string product_id, string sku_info, int quantity)
        {
            var content = new StringBuilder();

            content.Append("{")
            .Append('"' + "product_id" + '"' + ": " + '"' + product_id + '"').Append(",")
            .Append('"' + "sku_info" + '"' + ": " + '"' + product_id + '"').Append(",")
            .Append('"' + "quantity" + '"' + ": " + quantity).Append(",")
            .Append("}");
            var result = HttpTo.Post(string.Format("https://api.weixin.qq.com/merchant/stock/reduce?access_token={0}", access_token),
                                     content.ToString());

            return(result);
        }
Exemple #23
0
        /// <summary>
        /// 修改货架
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="shelf_id">货架ID</param>
        /// <param name="shelf_data">货架详情(字段说明详见增加货架)</param>
        /// <param name="shelf_banner">货架banner(图片需调用图片上传接口获得图片Url填写至此,否则修改货架失败)</param>
        /// <param name="shelf_name">货架名称</param>
        /// <returns>
        /// {
        /// "errcode":0,
        ///"errmsg":"success"
        ///}
        /// </returns>
        public static string Mod(string access_token, int shelf_id, object shelf_data, string shelf_banner, string shelf_name)
        {
            var content = new StringBuilder();

            content.Append("{")
            .Append('"' + "shelf_id" + '"' + ": " + shelf_id).Append(",")
            .Append('"' + "shelf_data" + '"' + ": " + shelf_data.ToJson()).Append(",")
            .Append('"' + "shelf_banner" + '"' + ": " + '"' + shelf_banner + '"').Append(",")
            .Append('"' + "shelf_name" + '"' + ": " + '"' + shelf_name + '"')
            .Append("}");
            var result = HttpTo.Post(string.Format("https://api.weixin.qq.com/merchant/shelf/mod?access_token={0}", access_token), content.ToString());

            return(result);
        }
Exemple #24
0
        /// <summary>
        /// 获取消息分送分时数据
        /// 最大时间跨度:1
        /// begin_date和end_date的差值需小于“最大时间跨度”(比如最大时间跨度为1时,begin_date和end_date的差值只能为0,才能小于1),否则会报错
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="begin_date">获取数据的起始日期,begin_date和end_date的差值需小于“最大时间跨度”(比如最大时间跨度为1时,begin_date和end_date的差值只能为0,才能小于1),否则会报错</param>
        /// <param name="end_date">获取数据的结束日期,end_date允许设置的最大值为昨日</param>
        /// <returns></returns>
        public static string GetUpStreamMsgHour(string access_token, DateTime begin_date, DateTime end_date)
        {
            var url     = string.Format("https://api.weixin.qq.com/datacube/getupstreammsghour?access_token={0}", access_token);
            var builder = new StringBuilder();

            builder
            .Append("{")
            .Append('"' + "begin_date" + '"' + ":").Append(begin_date.ToString("yyyy-MM-dd")).Append(",")
            .Append('"' + "end_date" + '"' + ":").Append(end_date.ToString("yyyy-MM-dd"))
            .Append("}");

            var result = HttpTo.Post(url, builder.ToString());

            return(result);
        }
Exemple #25
0
        /// <summary>
        /// 库存修改接口
        /// 增减某张卡券的库存。
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="card_id">卡券ID</param>
        /// <param name="increase_stock_value">增加多少库存,可以不填或填0</param>
        /// <param name="reduce_stock_value">减少多少库存,可以不填或填0</param>
        /// <returns>
        /// {
        ///"errcode":0,
        ///"errmsg":"ok"
        ///}
        ///</returns>
        public static string ModIfyStock(string access_token, string card_id, int increase_stock_value, int reduce_stock_value)
        {
            var url = string.Format("https://api.weixin.qq.com/card//modifystock?access_token={0}", access_token);

            var sb = new StringBuilder();

            sb.Append("{")
            .Append('"' + "card_id" + '"' + ":").Append(card_id)
            .Append('"' + "increase_stock_value" + '"' + ":").Append(increase_stock_value)
            .Append('"' + "reduce_stock_value" + '"' + ":").Append(reduce_stock_value)
            .Append("}");
            var result = HttpTo.Post(url, sb.ToString());

            return(result);
        }
Exemple #26
0
        /// <summary>
        /// 更新红包金额
        /// 支持领取红包后通过调用“更新红包”接口update红包余额。
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="code">红包的序列号</param>
        /// <param name="card_id">自定义code的卡券必填。非自定义code可不填。</param>
        /// <param name="balance">红包余额</param>
        /// <returns>
        /// {
        ///"errcode":0,
        ///"errmsg":"ok"
        ///}
        ///</returns>
        public static string UpdateUserBalance(string access_token, string code, string card_id, int balance)
        {
            var url = string.Format("https://api.weixin.qq.com/card/luckymoney/updateuserbalance?access_token={0}", access_token);

            var sb = new StringBuilder();

            sb.Append("{")
            .Append('"' + "code" + '"' + ":").Append(code)
            .Append('"' + "card_id" + '"' + ":").Append(card_id)
            .Append('"' + "balance" + '"' + ":").Append(balance)
            .Append("}");
            var result = HttpTo.Post(url, sb.ToString());

            return(result);
        }
Exemple #27
0
        /// <summary>
        /// 查询code
        ///
        /// 调用查询code接口可获取code的有效性(非自定义code),该code对应的用户openid、卡券有效期等信息。
        /// 自定义code(use_custom_code为true)的卡券调用接口时,post数据中需包含card_id,非自定义code不需上报。
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="code">要查询的序列号</param>
        /// <param name="card_id">要消耗序列号所述的card_id,生成券时use_custom_code填写true时必填。非自定义code不必填写。</param>
        /// <returns>{
        ///"errcode":0,
        ///"errmsg":"ok",
        ///"openid":"oFS7Fjl0WsZ9AMZqrI80nbIq8xrA",
        ///"card":{
        ///"card_id":"pFS7Fjg8kV1IdDz01r4SQwMkuCKc",
        ///"begin_time":1404205036,
        ///"end_time":1404205036,
        ///}
        ///}
        ///
        ///注:固定时长有效期会根据用户实际领取时间转换,如用户2013年10月1日领取,固定时长有效期为90天,即有效时间为2013年10月1日-12月29日有效。
        /// </returns>
        public static string Get(string access_token, string code, string card_id = "")
        {
            var url = string.Format("https://api.weixin.qq.com/card/get?access_token={0}", access_token);
            var sb  = new StringBuilder();

            sb.Append("{")
            .Append('"' + "code" + '"' + ":").Append(code);
            if (!string.IsNullOrEmpty(card_id))
            {
                sb.Append('"' + "card_id" + '"' + ":").Append(card_id);
            }
            sb.Append("}");
            var result = HttpTo.Post(url, sb.ToString());

            return(result);
        }
Exemple #28
0
        /// <summary>
        /// 会员卡交易
        /// 会员卡交易后每次积分及余额变更需通过接口通知微信,便于后续消息通知及其他扩展功能。
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="code">要消耗的序列号</param>
        /// <param name="add_bonus">需要变更的积分,扣除积分用“-“表示。</param>
        /// <param name="record_bonus">商家自定义积分消耗记录,不超过14个汉字。</param>
        /// <param name="add_balance">需要变更的余额,扣除金额用“-”表示。单位为分</param>
        /// <param name="record_balance">商家自定义金额消耗记录,不超过14个汉字。</param>
        /// <param name="card_id">要消耗序列号所述的card_id。自定义code的会员卡必填。</param>
        /// <returns>
        /// {
        ///"errcode":0,
        ///"errmsg":"ok",
        ///"result_bonus":100,
        ///"result_balance":200
        ///"openid":"oFS7Fjl0WsZ9AMZqrI80nbIq8xrA"
        ///}
        /// </returns>
        public static string UpdateUser(string access_token, string code, int add_bonus, string record_bonus, int add_balance, string record_balance, string card_id)
        {
            var url = string.Format("https://api.weixin.qq.com/card/membercard/updateuser?access_token={0}", access_token);

            var sb = new StringBuilder();

            sb.Append("{")
            .Append('"' + "code" + '"' + ":").Append(code)
            .Append('"' + "card_id" + '"' + ":").Append(card_id)
            .Append('"' + "record_bonus" + '"' + ":").Append(record_bonus)
            .Append('"' + "add_bonus" + '"' + ":").Append(add_bonus)
            .Append('"' + "add_balance" + '"' + ":").Append(add_balance)
            .Append('"' + "record_balance" + '"' + ":").Append(record_balance)
            .Append("}");
            var result = HttpTo.Post(url, sb.ToString());

            return(result);
        }
Exemple #29
0
        /// <summary>
        /// 公共API => 查询订单
        /// 不需要证书
        /// http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_2
        /// 该接口提供所有微信支付订单的查询,商户可以通过该接口主动查询订单状态,完成下一步的业务逻辑。
        /// 需要调用查询接口的情况:
        ///◆ 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知;
        ///◆ 调用支付接口后,返回系统错误或未知交易状态情况;
        ///◆ 调用被扫支付API,返回USERPAYING的状态;
        ///◆ 调用关单或撤销接口API之前,需确认支付状态;
        /// </summary>
        /// <param name="appid">(必填) String(32) 微信分配的公众账号ID</param>
        /// <param name="mch_id">(必填) String(32) 微信支付分配的商户号</param>
        /// <param name="transaction_id">String(32) 微信订单号 微信的订单号,优先使用 </param>
        /// <param name="out_trade_no">(transaction_id为空时必填) String(32) 商户订单号 商户系统内部的订单号,当没提供transaction_id时需要传这个。 </param>
        /// <param name="nonce_str">随机字符串 随机字符串,不长于32位。</param>
        /// <param name="partnerKey">API密钥</param>
        /// <returns> 参见:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_2 </returns>
        public static string OrderQuery(string appid, string mch_id, string transaction_id, string out_trade_no, string nonce_str, string partnerKey)
        {
            var stringADict = new Dictionary <string, string>
            {
                { "appid", appid },
                { "mch_id", mch_id },
                { "transaction_id", transaction_id },
                { "out_trade_no", out_trade_no },
                { "nonce_str", nonce_str }
            };
            var sign     = PayUtil.Sign(stringADict, partnerKey);//生成签名字符串
            var postdata = PayUtil.GeneralPostdata(stringADict, sign);
            var url      = "https://api.mch.weixin.qq.com/pay/orderquery";

            var result = HttpTo.Post(url, postdata);

            return(result);
        }
Exemple #30
0
        /// <summary>
        /// 公共API => 转换短链接
        /// 不需要证书
        /// http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_9
        ///应用场景
        ///该接口主要用于扫码原生支付模式一中的二维码链接转成短链接(weixin://wxpay/s/XXXXXX),减小二维码数据量,提升扫描速度和精确度。
        /// </summary>
        /// <param name="appid">(必填) String(32) 微信分配的公众账号ID</param>
        /// <param name="mch_id">(必填) String(32) 微信支付分配的商户号</param>
        /// <param name="long_url">(必填) String(512) URL链接 需要转换的URL,签名用原串,传输需URL encode  </param>
        /// <param name="nonce_str">(必填) 随机字符串 随机字符串,不长于32位。</param>
        /// <param name="partnerKey">(必填)API密钥</param>
        /// <returns> 参见:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_9 </returns>
        public static string ShortUrl(string appid, string mch_id, string long_url, string nonce_str,
                                      string partnerKey)
        {
            var stringADict = new Dictionary <string, string>
            {
                { "appid", appid },
                { "mch_id", mch_id },
                { "nonce_str", nonce_str },
                { "long_url", long_url }
            };

            var sign     = PayUtil.Sign(stringADict, partnerKey);//生成签名字符串
            var postdata = PayUtil.GeneralPostdata(stringADict, sign);
            var url      = "https://api.mch.weixin.qq.com/tools/shorturl";

            var result = HttpTo.Post(url, postdata);

            return(result);
        }