/// <summary> /// 预订单 /// </summary> /// <param name="pChannel"></param> /// <param name="pRequest"></param> public static PreOrderResponse PreOrder(WeiXinPayChannel pChannel, PreOrderRequest pRequest) { //参数检查 if (pChannel == null) { throw new ArgumentNullException("pChannel"); } if (pRequest == null) { throw new ArgumentNullException("pRequest"); } //创建预订单 var preOrderReq = pRequest.GetContent(pChannel); //获取访问授权 var token = WeiXinPay4AppGateway.GetAccessToken(pChannel.AppID, pChannel.AppSecret); if (!token.IsSuccess) { throw new WeiXinPayException("501", string.Format("获取访问授权失败:[微信接口返回的错误码={0};错误信息={1}].", token.ErrorCode, token.ErrorMessage)); } var url = string.Format("{0}access_token={1}", API_URL_OF_PREORDER, token.Token); var rsp = WeiXinPay4AppGateway.CallAPI <PreOrderResponse>(url, preOrderReq.ToJSON()); if (rsp.IsSuccess) { return(rsp); } else { throw new WeiXinPayException("502", string.Format("预订单失败:[微信接口返回的错误码={0};错误信息={1}].", rsp.ErrorCode, rsp.ErrorMessage)); } }
/// <summary> /// 创建预订单 /// <remarks> /// <para>与PreOrder的区别在于,此方法返回的信息包含App客户端调用微信SDK进行支付所必须的所有信息</para> /// </remarks> /// </summary> /// <param name="pChannel"></param> /// <param name="pRequest"></param> /// <returns></returns> public static PreOrderInfo CreatePreOrder(WeiXinPayChannel pChannel, WeiXinPayBaseRequest pRequest) { //参数检查 if (pChannel == null) { throw new ArgumentNullException("pChannel"); } if (pRequest == null) { throw new ArgumentNullException("pRequest"); } pRequest.Channel = pChannel; //创建预订单 var reqstr = pRequest.GetContent(); //获取访问授权 var token = WeiXinPay4AppGateway.GetAccessToken(pChannel.AppID, pChannel.AppSecret); if (!token.IsSuccess) { throw new WeiXinPayException("501", string.Format("获取访问授权失败:[微信接口返回的错误码={0};错误信息={1}].", token.ErrorCode, token.ErrorMessage)); } var url = string.Format("{0}access_token={1}", API_URL_OF_PREORDER, token.Token); var rsp = WeiXinPay4AppGateway.CallAPI <PreOrderResponse>(url, reqstr); if (!rsp.IsSuccess) { throw new WeiXinPayException("502", string.Format("预订单失败:[微信接口返回的错误码={0};错误信息={1}].", rsp.ErrorCode, rsp.ErrorMessage)); } // PreOrderInfo rtn = new PreOrderInfo(); rtn.AppID = pChannel.AppID; rtn.NonceStr = pRequest.NonceStr; rtn.PartnerID = pChannel.ParnterID; rtn.PreOrderID = rsp.PrePayID; rtn.TimeStamp = Convert.ToInt32(pRequest.TimeStamp); rtn.OrderSign = pRequest.AppSignature; // return(rtn); }
private void ConfigRequest(WeiXinPayChannel pChannel) { AppId = pChannel.AppID; }
public WeiXinPayRequest(WeiXinPayChannel pChannel) : this() { this.Channel = pChannel; }