public WeChatOpenIdCacheItem(string code, WeChatOpenId weChatOpenId)
 {
     Code         = code;
     WeChatOpenId = weChatOpenId;
 }
示例#2
0
 /// <summary>
 /// 微信公众号第二次跳转
 /// </summary>
 /// <param name="Oid">订单id</param>
 /// <param name="Code">微信回传的Code编码</param>
 private void TwoJump(int Oid, string Code)
 {
     try
     {
         String            AppId        = "";
         String            AppSecret    = "";
         String            UserId       = "";
         String            UserKey      = "";
         JMP.MDL.jmp_order morder       = new JMP.BLL.jmp_order().SelectOrderGoodsName(Oid, "jmp_order");
         WeChatOpenId      weChatOpenId = new WeChatOpenId();
         String            PayStr       = weChatOpenId.GetPayStr(morder.o_interface_id.ToString(), "WxGfGZH");
         UserId    = PayStr.ToString().Split(',')[0]; //商户号
         UserKey   = PayStr.ToString().Split(',')[1]; //api秘钥
         AppId     = PayStr.ToString().Split(',')[2]; //微信appid
         AppSecret = PayStr.ToString().Split(',')[3]; //微信app秘钥
         string openid = weChatOpenId.SelectOpendi(AppId, AppSecret, Code);
         if (!string.IsNullOrEmpty(openid))
         {
             Dictionary <string, string> List = new Dictionary <string, string>();
             List.Add("appid", AppId);                                                                                                           //微信appid
             List.Add("mch_id", UserId);                                                                                                         //商户号
             List.Add("nonce_str", morder.o_code);                                                                                               //随机字符串
             List.Add("body", morder.o_goodsname);                                                                                               //商品名称
             List.Add("out_trade_no", morder.o_code);                                                                                            //商户订单号
             List.Add("total_fee", (Convert.ToInt32(morder.o_price * 100)).ToString());                                                          //支付金额(单位:分)
             List.Add("spbill_create_ip", HttpContext.Current.Request.UserHostAddress);                                                          //ip地址
             int overtime = int.Parse(ConfigurationManager.AppSettings["overtime"].ToString());
             List.Add("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));                                                                    //交易起始时间
             List.Add("time_expire", DateTime.Now.AddSeconds(overtime).ToString("yyyyMMddHHmmss"));                                              //交易结束时间
             List.Add("notify_url", ConfigurationManager.AppSettings["WxTokenUrl"].ToString().Replace("{0}", morder.o_interface_id.ToString())); //异步通知地址
             List.Add("trade_type", "JSAPI");                                                                                                    //交易类型 NATIVE 微信扫码 JSAPI公众号
             List.Add("openid", openid);                                                                                                         //微信openid
             string signstr = JMP.TOOL.UrlStr.AzGetStr(List) + "&key=" + UserKey;
             string md5str  = JMP.TOOL.MD5.md5strGet(signstr, true).ToUpper();
             List.Add("sign", md5str);                                                    //签名
             string PostXmlStr = JMP.TOOL.xmlhelper.ToXml(List);
             string url        = ConfigurationManager.AppSettings["WxPayUrl"].ToString(); // 请求地址
             string Respon     = JMP.TOOL.postxmlhelper.postxml(url, PostXmlStr);
             Dictionary <string, object> dictionary = JMP.TOOL.xmlhelper.FromXml(Respon);
             if (dictionary.Count > 0 && dictionary["return_code"].ToString() == "SUCCESS" && dictionary["return_msg"].ToString() == "OK")
             {
                 CallJsApid(Oid, dictionary, UserKey, morder.o_showaddress);
             }
             else
             {
                 string wftzfsbxin = "微信官方公众号支付失败信息,错误信息:" + Respon;
                 PayApiDetailErrorLogger.UpstreamPaymentErrorLog("报错信息openid:" + openid + ":" + wftzfsbxin, summary: "微信官方公众号第二次跳转接口错误信息", channelId: Oid);
                 String str = "{\"Message\":\"支付通道异常\",\"ErrorCode\":104}";
                 Response.Write(str);
             }
         }
         else
         {
             Response.Write("非法访问!");
         }
     }
     catch (Exception ex)
     {
         PayApiDetailErrorLogger.UpstreamPaymentErrorLog("报错信息:" + ex.Message, summary: "微信官方公众号支付接口错误信息", channelId: Oid);
         Response.Write("非法访问!");
     }
 }