本文内容列表:
1.
2.肯德基appid和mch_id不 t配?
3.?
4.
5.(统一下单)
-java后端实现
-vu:下载地址
技术栈
板簧罩
Java语言(一种计算机语言,尤用于创建网站)
XML()
MD5签名
Opmch_appid的logo,)。
app _ id (idmch_appid,,登录——开发——基本配置获取mch_appid;)
Key(后台配置收款人,登录-账户中心-API安全-设置密钥,设置32位密钥值;)
Mch_id(收款人的商户号;)
C:。
统一订单
前端调出(需要加密)
订单结果的主动通知(回调接口)
查询订单结果
结束订单付款接口(关闭订单,关闭付款订单)
密码
。可以在官网下载例子,java程序也可以介绍。然而,github上的sdk在mch_appid已经很久没有更新了。最好的选择也是我的选择。在官网下载sdk项目,将所有java类复制到自己的项目中。
官网sdk下载目录
链接到:商家平台首页
# # # #根据。
创建IWxPayConfig.class,继承sdk WXPayConfig.class,在sdk中实现一些抽象方法,读取本地证书并加载到配置类中。
包core . com . chi dori . wx pay;
导入core . com . wx pay . iwx pay domain;
导入core . com . wx pay . wxpayconfig;导入core . com . wx pay . wx pay constants;
导入org . spring framework . beans . factory . annotation . value;
导入org . spring framework . stereotype . service;
导入Java . io . bytearray inputstream;
导入Java . io . file;
导入Java . io . file inputstream;
导入Java . io . inputstream;
@服务
公共类iwxpayconfig扩展WXPayConfig {//继承sdk WXPayConfig实现sdk中的一些抽象方法。
私有字节[]cert data;
@ Value( “$ { vendor . wx . config . app _ id } “)
私有字符串app _ id
@ Value( “$ { vendor . wx . pay . key } “)
私有字符串wx _ pay _ key
@ Value( “$ { vendor . wx . pay . mch _ id } “)
私有字符串wx _ pay _ mch _ id
公共iwxpayconfig()throws exception {//构造函数读取证书,sdk可以通过getCertStream获取证书。
字符串certPath = “/data/config/chi dori/API client _ cert . p12 “
File file =新文件(cert path);
InputStream certStream = new file InputStream(file);
this . certdata = new byte[(int)file . length()];
certstream . read(this . certdata);
certstream . close();
}
@覆盖
公共字符串getAppID() {
返回app _ id
}
@覆盖
公共字符串获取MchID() {
返回wx _ pay _ mch _ id
}
@覆盖
公共字符串getKey() {
返回wx _ pay _ key
}
@覆盖
公共输入流getCertStream() {
返回新的bytearray inputstream(this . certdata);
}
@覆盖
公共iwxpaydomain getwxpaydomain(){//这个方法需要这样实现,否则WXPay无常初始化。
IWXPayDomain IWXPayDomain = new IWXPayDomain(){
@覆盖
公共void报告(字符串域,长elapsedTimeMillis,Exception ex) {
}
@覆盖
公共域信息getDomain(WXPayConfig config) {
返回新的IWXPayDomain。DomainInfo(WXPayConstants。DOMAIN_API,true);
}
};
返回iwxPayDomain
}
}
发起统一订单,前端会调整。
//发起
WXPay wxpay = null
映射结果= new HashMap();
尝试{
// ******************************************
//
//统一排序
//
// ******************************************
wx pay = new wx pay(iWxPayConfig);//* * *注入自实现的,创建WXPay核心类,包含统一的订购接口。
map data = new HashMap();
数据上传( “身体与健康, “订单详情 “);
数据上传( “外贸编号 “,trans order . getglobaloderid());//唯一的订单号,不允许重复。重复的
数据上传( “总计_费用 “,string . value of(trans order . getorderamount()。multiply(新的BigDecimal(100))。int value()));//订单金额,以分钟为单位
数据上传( “创建ip “, “192 . 168 . 31 . 166 “);//下单ip
数据上传( “openid “,openId);//
数据上传( “通知_网址 “, ” “);//订单结果通知,。
数据上传( “贸易类型 “, “JSAPI和;”);//固定填充
logger . info( “发起,request = { } “,数据);
Map response = wxpay.unifiedOrder(数据);//,unifiedOrder接口,这里请求MD5加密方法。
logger . info( “,返回值为response = { } “,回应);
string return code = response . get(“return _ code “);
如果(!SUCCESS.equals(returnCode)) {
返回null
}
字符串result code = response . get( “结果代码);
如果(!SUCCESS.equals(resultCode)) {
返回null
}
字符串prepay _ id = response . get( “预付id “);
if (prepay_id == null) {
返回null
}
// ******************************************
//
//前端调出。
//
// ******************************************
字符串包= “预付费id = “预付费id;
Map wxPayMap =新哈希表p();
wx paymap . put( “appId “,iwxpayconfig . getappid());
wx paymap . put( “时间戳 “,string . value of(utility . getcurrenttimestamp());
wx paymap . put( “非中心 “,utility . generate uid());
wx paymap . put( “包装 “,包);
wx paymap . put( “符号类型和名称, “MD5 “);
//加密字符串包括五个参数,AppID timestamp nonce str package sign type,由sdk WXPayUtil类加密。注意,这里使用的是MD5加密方法。
string sign = wxpayutil . generate signature(wxPayMap,iwxpayconfig . getkey());
// ******************************************
//
//向前端返回调用。
//
// ******************************************
结果. put( “预付id “,prepay _ id);
结果. put( “标志与广告,签字);
result . putall(wx paymap);
返回结果;
} catch(异常e) {
}
回调结果处理
核心是回拨支付指令时检查加密签名是否匹配,防止出现模拟成功通知。
@ request mapping(value = “/pay callback “,方法=请求方法。帖子)
公共字符串payCallback(HttpServletRequest请求,HttpServletResponse响应){
logger . info( “异步通知进入 “);
字符串resXml = ” “
尝试{
//
InputStream is = request . getinputstream();
//Put InputStrea将m转换为字符串
buffered reader reader = new buffered reader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null
尝试{
while ((line = reader.readLine())!= null) {
某人追加(行 ” “);
}
} catch (IOException e) {
e . printstacktrace();
}最后{
尝试{
is . close();
} catch (IOException e) {
e . printstacktrac: { } “,resxml);
返回wxticketservice . pay back(resXml);
}catch(异常e){
logger . error( ” “,e);
字符串结果= ” “
返回结果;
}
}
@覆盖
公共字符串回收(String notifyData) {
logger . info( “payroll()start,notifyData = { } “,notify data);
String xmlBack = ” “
Map notifyMap = null
尝试{
wx pay wx pay = new wx pay(iWxPayConfig);
notify map = wxpayutil . XML tomap(notify data);//转换为地图
if(wx pay . ispayrmch_appid:订单已退款,但已收到支付成功结果通知。商家端的订单状态不应该从退款变为支付成功。
字符串返回_代码= notifymap . get( “return _ cod: { } “,notifymap);
xmlBack = ” “
返回xmlBack
}
//业务逻辑处理* * * * * * * * * * * * * * * * * * * * * * * * *
logg: { } “,通知地图);
xmlBack = ” “
返回xmlBack
}否则{
logger . error( “);
xmlBack = ” “
返回xmlBack
}
} catch(异常e) {
logger . error( ” “,e);
xmlBack = ” “
}
返回xmlBack
}
统一订单的签名和后续前端拉,也就是两者都用MD5加密。如果不一样,前端拉,这是一个巨大的坑。为此调试了很久,。
,调整如下::。
WXPay类需要修改加密判断。在WXPay构造方法中,调整如下。
公共WXPay(最终WXPayConfig配置、最终字符串notifyUrl、最终布尔autoReport、最终布尔useSandbox)引发异常{
this.config = config
this . notify URL = notify URL;
this.autoReport = autoReport
this . use sandbox = use sandbox;
if (useSandbox) {this.signType = SignType。MD5//沙盒环境
}
否则{
this.signType = SignType。MD5//将此处的加密方法更改为SignType。MD5,并与前端挂的。
}
this . WXPayRequest = new WXPayRequest(config);
}
结束语
完成之后,,但是在开发过程中难度很大。不清楚,加密。
肯德基appid和mch_id不匹配是什么意思
肯德基appid和mch_id不匹配意味着appid和mch_id没有绑定。Mch_id是与appid成对绑定的支付商户号,收款资金会进入这个商户号。
?
mch_id是成对绑定appid的支付商户号,归集的资金会进入商户号。
Appid必须是最后调出收银台的applet appid。
Trade_type请填写JSAPI。
Openid是appid对应的用户id,也就是使用wx.login接口获得的openid。
扩展数据
第三方服务商申请自己的服务号appid,通过这个服务号appid申请服务商mch_id,从而获得。
然后服务商mch_id申请为其服务的特约商户创建一个,创建的sub_mch_id默认与服务商mch_id建立父子授权关系。
这样就可以利用,为特约商户和用户提供服务。
同时,每个 “mch_id-sub_mch_id父子授权关系 “,包括不限于支付授权目录、appid推荐关注、sub_appid等。
以小程序支付为例。哪个appl
//
/**
*
* @param body产品描述
* @param out_trade_no订单编号
* @paramTotal _费用金额(分钟)
* @param objectStr附加字段
* @ param loca _ ip user 的实际ip地址
* @返回
* @抛出异常
*/
公共静态ReturnData wxAppPay(String body,Stringout_trade_no,Integertotal_fee,String objectStr,Stringloca_ip)引发异常{
ReturnData结果= new return data();
string nonce _ str = getRandomString(32);//随机字符串
//包参数
SortedMapString,String sign params = new TreeMapString,String();
sign params . put( “appid “,wechatconfig . appid);//
sign params . put( “mch _ id “,we chat config . mch _ id);//
sign params . put( “nonce _ str “,nonce _ str);//随机字符串,不超过32位。
sign params . put( “身体与健康,正文);//产品描述
sign params . put( “附加 “,objectStr);//附加数据按查询API和付款通知中的原样返回。
sign params . put( “外贸编号 “,out _ trade _ no);//商户系统内部订单号
sign params . put( “总计_费用 “,string . value of(total _ fee));//以分钟为单位的订单总额。
sign params . put( “创建ip “,loca _ IP);//客户端的实际ip
sign params . put( “通知_网址 “,we chat config . notify _ URL);//异步接收
sign params . put( “贸易类型 “, “APP “);//付款类型
logger . info( “: “JSONObject。tojsonstring(Sign Params));
string sign = weixinpayutil . create sign( “UTF-8 “,signParams,we chat config . key);//生成签名
sign params . put( “标志与广告,签字);/签名
string request XML = weixinpayutil . getrequest XML(sign params);//生成Xml格式的字符串
//调用统一支付接口
//request XML = new String(request XML . getbytes( “utf-8和)、 “ISO-8859-1和”);//出现时使用。
string resXml = http util . post( ” “,request XML);
//付款返回
//返回结果的成功结果取出prepay_id:
map map = XML util . doxmlprase(resXml);
String return _ code =(String)map . get( “return _ code “);
if(return _ code . contains( “成功 “)) {
String prepay _ id =(String)map . get( “预付id “);//获取预付款标识(预付款标识)
string timestamp = string . value of(system . current time millis()/1000);
SortedMapString,String sign param = new TreeMapString,String();
sign param . put( “appid “,wechatconfig . appid);// app_id
sign param . put( “合伙人公司,. mch_ id);//
sign param . put( “预付 “,prepay _ id);//预付订单id
sign param . put( “包装 “, “Sign = WXPay “);//默认符号=WXPay
sign param . put( “非中心 “,nonce _ str);//自定义不重复长度不超过32位。
sign param . put( “时间戳 “,时间戳);//北京时间戳记
string sign again = weixinpayutil . create sign( “UTF-8 “,signParam,we chat config . key);//再次生成签名
sign param . put( “标志与广告,sign again);
JSON object return param = JSON object . parse object(JSON object . tojsonstring(sign param));
logger . info( “: “return param . tostring());
result . set code(200);
result . setdata(return param . tostring());
}否则{
result . setmsg((String)map . get( “return _ msg “));
result . set cod
(统一下单)
第一次开发mch_appid,遇到mch_appid这个签名错误,所以让 让我们把它记录在这里。
界面链接mch_appid:
:
统一订购官网地址L:
发送xml参数
其中appid查找当前applet的appid。
Mch_id,是当前商家号的id。
Spbill_crmch_appid半天,发现需要在商家平台重置api密钥。
It 这是因为最后签名的密钥。
我第一次在mch_appid设置这个密钥,但是它总是显示错误的签名。今天重置了,再次请求后错误被解决。
注意:一定要有对应的小程序和商户号,否则也会出现问题。
那个 mch _ appid和的介绍结束。不知道你有没有从中找到你需要的信息?如果你想了解更多这方面的内容,记得收藏并关注这个网站。可以点击下面的广告链接,输入需要专属的id。一人一号专属。
未经允许不得转载:头号研究社-海外苹果ID购买注册|海外苹果礼品卡及Arcade订阅|海外账号购买、教程 » 包含mch_appid的条目