小程序
小游戏
企业微信
微信支付
扫描小程序码分享
小程序调起支付的时候,扫码之后就返回“商户传入的appid参数不正确,请联系商户处理“
在获取用户的openid 的时候,用的是小程序的appid 和secret
但是支付接口返回的appid 是我公众号的appid, 这样就导致了 openid 和 我的appid 不一致了,请问下这要怎么处理
1 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
小程序支付用的appid是小程序的appid,不是公众号的appid, oppid也是通过小程序的appid去获取的
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
是的,我的openid 是小程序的appenid 获取的,但是我请求支付进口后,返回给我的appid 变成了 公众号的appid ,这就导致我前端发起支付的时候返回 ‘’商户传入的appid参数不正确,请联系商户处理
算了给你看下我的c#后台,把数据参数改掉就可以了
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.IO;
using System.Security.Cryptography;
using System.Xml;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.WebApp.Areas.CommonModule.Controllers;
namespace System.WebApp.Areas.CommonModule.Controllers
{
public class wxController : Controller
//
// GET: /wx/
public ActionResult Index()
return View();
}
//所需值
public static string _appid = "*****";
public static string _mch_id = "*****";//
public static string _key = "*****";
public static string openid = "****";
//模拟wx统一下单 openid(前台获取)
public string getda(string openid)
return Getprepay_id(_appid, "shanghaifendian", "monixiaofei", _mch_id, GetRandomString(30), "http://www.weixin.qq.com/wxpay/pay.php", openid, getRandomTime(), 1);
//微信统一下单获取prepay_id & 再次签名返回数据
private static string Getprepay_id(string appid, string attach, string body, string mch_id, string nonce_str, string notify_url, string openid, string bookingNo, int total_fee)
var url = "https://api.mch.weixin.qq.com/pay/unifiedorder";//微信统一下单请求地址
string ss = "http://wxpay.wxutil.com/pub_v2/pay/notify.v2.php";
string strA = "appid=" + _appid + "&body=test&device_info=1000&mch_id=" + _mch_id + "&nonce_str=" + nonce_str + "¬ify_url=" + ss + "&openid=" + openid + "&out_trade_no=" + bookingNo + "&total_fee=1&trade_type=JSAPI";
string strk = strA + "&key="+_key; //key为商户平台设置的密钥key(假)
string strMD5 = MD5(strk).ToUpper();//MD5签名
var formData = "<xml>";
formData += "<appid>" + _appid + "</appid>";
formData += "<mch_id>" + mch_id + "</mch_id>";
formData += "<device_info>1000</device_info>";
formData += "<body>test</body>";
formData += "<nonce_str>" + nonce_str + "</nonce_str>";
formData += "http://wxpay.wxutil.com/pub_v2/pay/notify.v2.php";//通知地址
formData += "<openid>" + openid + "</openid>";//openid
formData += "<out_trade_no>" + bookingNo + "</out_trade_no>";//商户订单号 --待
formData += "<total_fee>1</total_fee>";//支付金额单位为(分)
formData += "<trade_type>JSAPI</trade_type>";//交易类型(JSAPI--公众号支付)
formData += "<sign>" + strMD5 + "</sign>";
formData += "</xml>";
//请求数据
var getdata = sendPost(url, formData);
//获取xml数据
XmlDocument doc = new XmlDocument();
doc.LoadXml(getdata);
//xml格式转json
string json = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc);
JObject jo = (JObject)JsonConvert.DeserializeObject(json);
string prepay_id = jo["xml"]["prepay_id"]["#cdata-section"].ToString();
//时间戳
string _time = getTime().ToString();
string zz = "prepay_id=" + prepay_id;
//再次签名返回数据至小程序
// string strB = "appId=" + appid + "&nonceStr=" + nonce_str + "&package=prepay_id=" + prepay_id + "&signType=MD5&timeStamp=" + _time + "&key="+_key;
string strB = "appId=" + appid + "&nonceStr=" + nonce_str + "&package=" + zz + "&signType=MD5&timeStamp=" + _time + "&key=" + _key;
//wx自己写的一个类
wx w = new wx();
w.timeStamp = _time;
w.nonceStr = nonce_str;
w.package = zz;
w.paySign = MD5(strB).ToUpper(); ;
w.signType = "MD5";
//向小程序返回json数据
return JsonConvert.SerializeObject(w);
/// <summary>
/// 生成随机串
/// </summary>
/// <param name="length">字符串长度</param>
/// <returns></returns>
private static string GetRandomString(int length)
const string key = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
if (length < 1)
return string.Empty;
Random rnd = new Random();
byte[] buffer = new byte[8];
ulong bit = 31;
ulong result = 0;
int index = 0;
StringBuilder sb = new StringBuilder((length / 5 + 1) * 5);
while (sb.Length < length)
rnd.NextBytes(buffer);
buffer[5] = buffer[6] = buffer[7] = 0x00;
result = BitConverter.ToUInt64(buffer, 0);
while (result > 0 && sb.Length < length)
index = (int)(bit & result);
sb.Append(key[index]);
result = result >> 5;
return sb.ToString();
/// 获取时间戳
private static long getTime()
TimeSpan cha = (DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)));
long t = (long)cha.TotalSeconds;
return t;
/// MD5签名方法
/// <param name="inputText">加密参数</param>
private static string MD5(string inputText)
MD5 md5 = new MD5CryptoServiceProvider();
byte[] fromData = System.Text.Encoding.UTF8.GetBytes(inputText);
byte[] targetData = md5.ComputeHash(fromData);
string byte2String = null;
for (int i = 0; i < targetData.Length; i++)
byte2String += targetData[i].ToString("x2");
return byte2String;
/// HMAC-SHA256签名方式
/// <param name="message"></param>
/// <param name="secret"></param>
private static string HmacSHA256(string message, string secret)
secret = secret ?? "";
var encoding = new System.Text.UTF8Encoding();
byte[] keyByte = encoding.GetBytes(secret);
byte[] messageBytes = encoding.GetBytes(message);
using (var hmacsha256 = new HMACSHA256(keyByte))
byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
return Convert.ToBase64String(hashmessage);
/// wx统一下单请求数据
/// <param name="URL">请求地址</param>
/// <param name="urlArgs">参数</param>
private static string sendPost(string URL, string urlArgs)
System.Net.WebClient wCient = new System.Net.WebClient();
wCient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
//byte[] postData = System.Text.Encoding.ASCII.GetBytes(urlArgs); 如果微信签名中有中文会签名失败
byte[] postData = System.Text.Encoding.UTF8.GetBytes(urlArgs);
byte[] responseData = wCient.UploadData(URL, "POST", postData);
string returnStr = System.Text.Encoding.UTF8.GetString(responseData);//返回接受的数据
return returnStr;
/// 生成订单号
private static string getRandomTime()
Random rd = new Random();//用于生成随机数
string DateStr = DateTime.Now.ToString("yyyyMMddHHmmssMM");//日期
string str = DateStr + rd.Next(10000).ToString().PadLeft(4, '0');//带日期的随机数
return str;
您好,除了上面开发者的分享,还有如果是礼品卡小程序还需要注意:目前一个商户号只能绑定了一个礼品卡小程序。
请问,你这个问题解决了,我也出现了跟你一样的问题,请教一下解决方案
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
小程序支付用的appid是小程序的appid,不是公众号的appid, oppid也是通过小程序的appid去获取的
是的,我的openid 是小程序的appenid 获取的,但是我请求支付进口后,返回给我的appid 变成了 公众号的appid ,这就导致我前端发起支付的时候返回 ‘’商户传入的appid参数不正确,请联系商户处理
算了给你看下我的c#后台,把数据参数改掉就可以了
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.IO;
using System.Security.Cryptography;
using System.Xml;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.WebApp.Areas.CommonModule.Controllers;
namespace System.WebApp.Areas.CommonModule.Controllers
{
public class wxController : Controller
{
//
// GET: /wx/
public ActionResult Index()
{
return View();
}
//所需值
public static string _appid = "*****";
public static string _mch_id = "*****";//
public static string _key = "*****";
public static string openid = "****";
//模拟wx统一下单 openid(前台获取)
public string getda(string openid)
{
return Getprepay_id(_appid, "shanghaifendian", "monixiaofei", _mch_id, GetRandomString(30), "http://www.weixin.qq.com/wxpay/pay.php", openid, getRandomTime(), 1);
}
//微信统一下单获取prepay_id & 再次签名返回数据
private static string Getprepay_id(string appid, string attach, string body, string mch_id, string nonce_str, string notify_url, string openid, string bookingNo, int total_fee)
{
var url = "https://api.mch.weixin.qq.com/pay/unifiedorder";//微信统一下单请求地址
string ss = "http://wxpay.wxutil.com/pub_v2/pay/notify.v2.php";
string strA = "appid=" + _appid + "&body=test&device_info=1000&mch_id=" + _mch_id + "&nonce_str=" + nonce_str + "¬ify_url=" + ss + "&openid=" + openid + "&out_trade_no=" + bookingNo + "&total_fee=1&trade_type=JSAPI";
string strk = strA + "&key="+_key; //key为商户平台设置的密钥key(假)
string strMD5 = MD5(strk).ToUpper();//MD5签名
var formData = "<xml>";
formData += "<appid>" + _appid + "</appid>";
formData += "<mch_id>" + mch_id + "</mch_id>";
formData += "<device_info>1000</device_info>";
formData += "<body>test</body>";
formData += "<nonce_str>" + nonce_str + "</nonce_str>";
formData += "http://wxpay.wxutil.com/pub_v2/pay/notify.v2.php ";//通知地址
formData += "<openid>" + openid + "</openid>";//openid
formData += "<out_trade_no>" + bookingNo + "</out_trade_no>";//商户订单号 --待
formData += "<total_fee>1</total_fee>";//支付金额单位为(分)
formData += "<trade_type>JSAPI</trade_type>";//交易类型(JSAPI--公众号支付)
formData += "<sign>" + strMD5 + "</sign>";
formData += "</xml>";
//请求数据
var getdata = sendPost(url, formData);
//获取xml数据
XmlDocument doc = new XmlDocument();
doc.LoadXml(getdata);
//xml格式转json
string json = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc);
JObject jo = (JObject)JsonConvert.DeserializeObject(json);
string prepay_id = jo["xml"]["prepay_id"]["#cdata-section"].ToString();
//时间戳
string _time = getTime().ToString();
string zz = "prepay_id=" + prepay_id;
//再次签名返回数据至小程序
// string strB = "appId=" + appid + "&nonceStr=" + nonce_str + "&package=prepay_id=" + prepay_id + "&signType=MD5&timeStamp=" + _time + "&key="+_key;
string strB = "appId=" + appid + "&nonceStr=" + nonce_str + "&package=" + zz + "&signType=MD5&timeStamp=" + _time + "&key=" + _key;
//wx自己写的一个类
wx w = new wx();
w.timeStamp = _time;
w.nonceStr = nonce_str;
w.package = zz;
w.paySign = MD5(strB).ToUpper(); ;
w.signType = "MD5";
//向小程序返回json数据
return JsonConvert.SerializeObject(w);
}
/// <summary>
/// 生成随机串
/// </summary>
/// <param name="length">字符串长度</param>
/// <returns></returns>
private static string GetRandomString(int length)
{
const string key = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
if (length < 1)
return string.Empty;
Random rnd = new Random();
byte[] buffer = new byte[8];
ulong bit = 31;
ulong result = 0;
int index = 0;
StringBuilder sb = new StringBuilder((length / 5 + 1) * 5);
while (sb.Length < length)
{
rnd.NextBytes(buffer);
buffer[5] = buffer[6] = buffer[7] = 0x00;
result = BitConverter.ToUInt64(buffer, 0);
while (result > 0 && sb.Length < length)
{
index = (int)(bit & result);
sb.Append(key[index]);
result = result >> 5;
}
}
return sb.ToString();
}
/// <summary>
/// 获取时间戳
/// </summary>
/// <returns></returns>
private static long getTime()
{
TimeSpan cha = (DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)));
long t = (long)cha.TotalSeconds;
return t;
}
/// <summary>
/// MD5签名方法
/// </summary>
/// <param name="inputText">加密参数</param>
/// <returns></returns>
private static string MD5(string inputText)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] fromData = System.Text.Encoding.UTF8.GetBytes(inputText);
byte[] targetData = md5.ComputeHash(fromData);
string byte2String = null;
for (int i = 0; i < targetData.Length; i++)
{
byte2String += targetData[i].ToString("x2");
}
return byte2String;
}
/// <summary>
/// HMAC-SHA256签名方式
/// </summary>
/// <param name="message"></param>
/// <param name="secret"></param>
/// <returns></returns>
private static string HmacSHA256(string message, string secret)
{
secret = secret ?? "";
var encoding = new System.Text.UTF8Encoding();
byte[] keyByte = encoding.GetBytes(secret);
byte[] messageBytes = encoding.GetBytes(message);
using (var hmacsha256 = new HMACSHA256(keyByte))
{
byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
return Convert.ToBase64String(hashmessage);
}
}
/// <summary>
/// wx统一下单请求数据
/// </summary>
/// <param name="URL">请求地址</param>
/// <param name="urlArgs">参数</param>
/// <returns></returns>
private static string sendPost(string URL, string urlArgs)
{
System.Net.WebClient wCient = new System.Net.WebClient();
wCient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
//byte[] postData = System.Text.Encoding.ASCII.GetBytes(urlArgs); 如果微信签名中有中文会签名失败
byte[] postData = System.Text.Encoding.UTF8.GetBytes(urlArgs);
byte[] responseData = wCient.UploadData(URL, "POST", postData);
string returnStr = System.Text.Encoding.UTF8.GetString(responseData);//返回接受的数据
return returnStr;
}
/// <summary>
/// 生成订单号
/// </summary>
/// <returns></returns>
private static string getRandomTime()
{
Random rd = new Random();//用于生成随机数
string DateStr = DateTime.Now.ToString("yyyyMMddHHmmssMM");//日期
string str = DateStr + rd.Next(10000).ToString().PadLeft(4, '0');//带日期的随机数
return str;
}
}
}
您好,除了上面开发者的分享,还有如果是礼品卡小程序还需要注意:目前一个商户号只能绑定了一个礼品卡小程序。
请问,你这个问题解决了,我也出现了跟你一样的问题,请教一下解决方案