/// <summary> /// 从统一下单成功返回的数据中获取微信浏览器调起jsapi支付所需的参数, /// 微信浏览器调起JSAPI时的输入参数格式如下: /// { /// "appId" : "wx2421b1c4370ec43b", //公众号名称,由商户传入 /// "timeStamp":" 1395712654", //时间戳,自1970年以来的秒数 /// "nonceStr" : "e61463f8efa94090b1f366cccfbbb444", //随机串 /// "package" : "prepay_id=u802345jgfjsdfgsdg888", /// "signType" : "MD5", //微信签名方式: /// "paySign" : "70EA570631E4BB79628FBCA90534C63FF7FADD89" //微信签名 /// } /// @return string 微信浏览器调起JSAPI时的输入参数,json格式可以直接做参数用 /// 更详细的说明请参考网页端调起支付API:http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7 /// </summary> /// <returns></returns> public string GetJsApiParameters() { WxPayLog.Debug(TypeString + ".GetJsApiParameters", "JsApiPay::GetJsApiParam is processing..."); WxPayData jsApiParam = new WxPayData(); jsApiParam.SetValue("appId", unifiedOrderResult.GetValue("appid")); jsApiParam.SetValue("timeStamp", WxPayApi.GenerateTimeStamp()); jsApiParam.SetValue("nonceStr", WxPayApi.GenerateNonceStr()); jsApiParam.SetValue("package", "prepay_id=" + unifiedOrderResult.GetValue("prepay_id")); jsApiParam.SetValue("signType", "MD5"); jsApiParam.SetValue("paySign", jsApiParam.MakeSign()); string parameters = jsApiParam.ToJson(); WxPayLog.Debug(TypeString + ".GetJsApiParameters", "Get jsApiParam : " + parameters); return(parameters); }
/// <summary> /// 获取收货地址js函数入口参数,详情请参考收货地址共享接口:http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_9 /// 调用js获取收货地址时需要传入的参数 /// 格式:json串 /// 包含以下字段: /// appid:公众号id /// scope: 填写“jsapi_address”,获得编辑地址权限 /// signType:签名方式,目前仅支持SHA1 /// addrSign: 签名,由appid、url、timestamp、noncestr、accesstoken参与签名 /// timeStamp:时间戳 /// nonceStr: 随机字符串 /// </summary> /// <returns>共享收货地址js函数需要的参数,json格式可以直接做参数使用</returns> public string GetEditAddressParameters() { string parameter = ""; try { //这个地方要注意,参与签名的是网页授权获取用户信息时微信后台回传的完整url string url = "http://" + UrlHost + Path + UrlQuery; //构造需要用SHA1算法加密的数据 WxPayData signData = new WxPayData(); signData.SetValue("appid", WxPayConfig.APPID); signData.SetValue("url", url); signData.SetValue("timestamp", WxPayApi.GenerateTimeStamp()); signData.SetValue("noncestr", WxPayApi.GenerateNonceStr()); signData.SetValue("accesstoken", access_token); string param = signData.ToUrl(); WxPayLog.Debug(TypeString + ".GetEditAddressParameters", "SHA1 encrypt param : " + param); //SHA1加密 string addrSign = Sha1Hash(param); WxPayLog.Debug(TypeString + ".GetEditAddressParameters", "SHA1 encrypt result : " + addrSign); //获取收货地址js函数入口参数 WxPayData afterData = new WxPayData(); afterData.SetValue("appId", WxPayConfig.APPID); afterData.SetValue("scope", "jsapi_address"); afterData.SetValue("signType", "sha1"); afterData.SetValue("addrSign", addrSign); afterData.SetValue("timeStamp", signData.GetValue("timestamp")); afterData.SetValue("nonceStr", signData.GetValue("noncestr")); //转为json格式 parameter = afterData.ToJson(); WxPayLog.Debug(TypeString + ".GetEditAddressParameters", "Get EditAddressParam : " + parameter); } catch (Exception ex) { WxPayLog.ErrorThrow(TypeString + ".GetEditAddressParameters", ex.ToString()); } return(parameter); }