微信支付---APP調起微信支付c#後臺接口

                            c#後臺APP微信支付接口和微信公衆號支付差不多

  #region 微信APP支付接口
        /// <summary>
        /// 微信APP支付接口
        /// </summary>
        /// <param name="out_trade_no">支付訂單號</param
        /// <param name="total_fee">支付金額</param>
        /// <param name="type">1.安卓,2.IOS</param>
        /// <returns></returns>
        [HttpGet]
        public CommonResponse<Wx_pay> APP_Pay(string out_trade_no,Double total_fee,int type)
        {
            PayMent pm = new PayMent();
            string ip = HttpContext.Current.Request.UserHostAddress;
            int money =int.Parse((total_fee * 100).ToString());
            Wx_pay wp = pm.APP_PayMent("服務費",ip,money,out_trade_no,type);
            if (wp.sign == "") {
                return new CommonResponse<Wx_pay> { Data = null, Message = "系統異常,聯繫管理員!", Code = EnumResponseCode.Fail.GetHashCode() };
            }
            return new CommonResponse<Wx_pay> { Data = wp, Message = String.Empty, Code = EnumResponseCode.Successful.GetHashCode() };
        }
        #endregion 
        
       ///
       ///是對返回數據類型
       ///
     public class CommonResponse<T> 
    {
        public T Data { get; set; }
        
          /// <summary>
        /// 代碼  1:失敗,2:成功
        /// </summary>

        public int Code { get; set; }
        /// <summary>
        /// 消息
        /// </summary>

        public string Message { get; set; }

        /// <summary>
        /// 其他附帶信息
        /// </summary>

        public string Tag { get; set; }
        
    }
       
        /// <summary>
    /// 微信APP支付實體
    /// </summary>
  public class Wx_pay
    {
        /// <summary>
        /// 應用ID
        /// </summary>
        public string appid { set; get; } = "";
        /// <summary>
        /// 商戶號
        /// </summary>
        public string partnerid { set; get; } = "";
        /// <summary>
        /// 預支付交易會話ID
        /// </summary>
        public string prepayid { set; get; } = "";
        /// <summary>
        /// 擴展字段
        /// </summary>
        public string package { set; get; } = "Sign=WXPay";
        /// <summary>
        /// 隨機字符串
        /// </summary>
        public string noncestr { set; get; } = "";
        /// <summary>
        /// 時間戳
        /// </summary>
        public string timestamp { set; get; } = "";

        /// <summary>
        /// 簽名
        /// </summary>
        public string sign { set; get; } = "";
    }
       
       
       
       
             #region 微信APP支付
        /// <summary>
        /// 微信APP支付
        /// </summary>
        /// <param name="boby">商品描述</param>
        /// <param name="mch_id">商戶號</param>
        /// <param name="spbill_create_ip">終端IP</param>
        /// <param name="total_fee">金額</param>
        /// <param name="out_trade_no">商戶訂單號</param>
        /// <returns></returns>
        public Wx_pay APP_PayMent( string boby,  string spbill_create_ip, int total_fee, string out_trade_no,int type)
       {
           UnifiedOrder order = new UnifiedOrder();
            if (type == 1)
            {
                order.appid = APP_Aconfig.appid;
                order.mch_id = APP_Aconfig.partnerid;
            }
            else {
                order.appid = APP_Iconfig.appid;
                order.mch_id = APP_Iconfig.partnerid;
            }
           order.attach = "APP名稱-支付內容說明";
           order.body = boby;
           order.device_info = "WEB";
           order.nonce_str = TenpayUtil.getNoncestr();
           order.notify_url = APP_Aconfig.url;
           order.out_trade_no = out_trade_no;
           order.trade_type = "APP";
           order.spbill_create_ip = spbill_create_ip;
           order.total_fee = total_fee;
           TenpayUtil tenpay = new TenpayUtil();
            string paySignKey = string.Empty;
            if (type == 1)
            {
                paySignKey = APP_Aconfig.paysignkey;
            }
            else {
                 paySignKey = APP_Iconfig.paysignkey;
            }
           string prepay_id = tenpay.getPrepay_id(order, paySignKey);       
           string timeStamp = TenpayUtil.getTimestamp();
           string nonceStr = TenpayUtil.getNoncestr();
           SortedDictionary<string, object> sParams = new SortedDictionary<string, object>();
           sParams.Add("appid", order.appid);
          sParams.Add("partnerid", order.mch_id);
            sParams.Add("prepayid", prepay_id);           
           sParams.Add("noncestr", nonceStr);
            sParams.Add("timestamp", timeStamp);
            sParams.Add("package", "Sign=WXPay");
           string paySign = tenpay.getsign(sParams, paySignKey);
            Wx_pay wp = new Wx_pay();
            wp.appid = order.appid;
            wp.partnerid = order.mch_id;
            wp.noncestr = nonceStr;
            wp.prepayid = prepay_id;
            wp.sign = paySign;
            wp.timestamp = timeStamp;
            return wp;
       }
        #endregion
        
         /// <summary>
    /// APP安卓支付配置
    /// </summary>
    public class APP_Aconfig
    {
        public const string appid = "";//APPID
        public const string partnerid = "";//商戶號
        public const string paysignkey = "";//證書密匙
        public const string url = "";//回調ur
    }
        
         /// <summary>
    /// APPios 支付配置
    /// </summary>
    public class APP_Iconfig
    {
        public const string appid = "";//APPID
        public const string partnerid = "";//商戶號
        public const string paysignkey = "";//證書密匙
        public const string url = "";//回調url
    }
        
        
        對於   TenpayUtil tenpay = new TenpayUtil();這個類其他文章上有代碼。
        
請求方式:http get         
接口參數說明
名稱    類型    必填    說明    
out_trade_no    string    是    支付訂單ID    
total_fee    Double    是    支付金額    
type    int    是    1.安卓,2.IOS    
 
返回示例:
/****失敗示例**/
{
"Code":1, /*狀態碼  1:失敗 2:成功 */
"Message":"錯誤信息",/*消息(一般失敗時,返回錯誤信息)*/
"Tag":""/*附加信息*/
}
 
 
 
/****成功示例**/
{
"Code":2, /*狀態碼  1:失敗 2:成功*/
“Data”:[]
"Message":"",/*消息(一般失敗時,返回錯誤信息)*/
"Tag":"附加信息"/* */
}
接口返回Data集合參數說明
名稱    類型    說明    
appid    string    應用ID    
partnerid    String     商戶號    
prepayid    String    預支付交易會話ID    
package    String    擴展字段    
noncestr    String    隨機字符串    
timestamp    String    時間戳    
sign    String    簽名    
 
 
 
 
 
 本人還是個新手(剛入行不久),請多多關照,後續還有微信其他內容
 相關項目地址:https://gitee.com/qq-w/wechat.git


這是測試接口返回結果:

blob.png


下篇。。。。。。微信支付(PC端掃碼支付)



blob.png

blob.png

blob.png

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章