Example #1
0
        /// <summary>
        /// 扫码支付(模式一)
        /// 官方文档:https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_1
        /// </summary>
        /// <returns></returns>
        public ActionResult NativePayOne(string productId)
        {
            try
            {
                if (string.IsNullOrEmpty(productId))
                {
                    return(Json(new { Code = 1, Msg = "产品不能为空!" }));
                }

                SortedDictionary <string, object> data = new SortedDictionary <string, object>
                {
                    { "appid", appid },
                    { "mch_id", mch_id },
                    { "time_stamp", PayHelper.Time_stamp },
                    { "nonce_str", PayHelper.Nonce_str },
                    { "product_id", productId }
                };
                data.Add("sign", PayHelper.MakeSign(data));

                return(Json(new { Code = 0, Msg = "weixin://wxpay/bizpayurl?" + PayHelper.ToUrl(data) }));
            }
            catch (Exception ex)
            {
                LogHelper.SaveLog(ex);
                return(Json(new { Code = 1, Msg = "服务器异常,请联系管理员!" }));
            }
        }
Example #2
0
        /**
         *
         * 获取收货地址js函数入口参数,详情请参考收货地址共享接口:http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_9
         * @return string 共享收货地址js函数需要的参数,json格式可以直接做参数使用
         */
        public string JsApiPayAddress(string access_token)
        {
            //参与签名的是网页授权获取用户信息时微信后台回传的完整url
            string url = "http://redirect_uri";

            //构造需要用SHA1算法加密的数据
            SortedDictionary <string, object> data = new SortedDictionary <string, object>
            {
                { "appid", appid },
                { "url", url },
                { "timestamp", PayHelper.Time_stamp },
                { "noncestr", PayHelper.Nonce_str },
                { "accesstoken", access_token }
            };
            string addrSign = EncryptHelper.SHA1(PayHelper.ToUrl(data));

            //获取收货地址js函数入口参数
            SortedDictionary <string, object> afterData = new SortedDictionary <string, object>
            {
                { "appId", appid },
                { "scope", "jsapi_address" },
                { "signType", "sha1" },
                { "addrSign", addrSign },
                { "timeStamp", data["timestamp"] },
                { "nonceStr", data["noncestr"] }
            };

            return(JsonConvert.SerializeObject(afterData));
        }