最近做一个PC端网上商城,需要微信扫码支付,几经摸索,终于搞出来了,现将代码贴下,以供参考!
1.扫码支付演示
看起来很简单,其实实现起来也不难,soEasy!
2.将生成二维码的js导入到项目
jquery.qrcode.min.js
3.在后台建一个微信参数配置
支付链接:
4.代码实现
4.1 微支付实体类WxPayConfig
public class WxPayConfig extends BaseEntity {
private static final long serialVersionUID = 1L;
/** appid */
private String appId;
/** 商户号 */
private String mchId;
/** 订单名称 */
private String body;
/** 设备信息 */
private String deviceInfo;
/** 交易类型 */
private String tradeType;
/** 支付链接 */
private String notifyUrl;
/** 店铺服务器ip */
private String spbillCreateIp;
/** 支付秘钥 */
private String privateKey;
/** 商户证书 */
private String securityCertificate;
/** 退款资金来源
* REFUND_SOURCE_UNSETTLED_FUNDS---未结算资金退款(默认使用未结算资金退款)
* REFUND_SOURCE_RECHARGE_FUNDS ---可用余额退款
*/
private String refundAccount;
public WxPayConfig(){}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getMchId() {
return mchId;
}
public void setMchId(String mchId) {
this.mchId = mchId;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getDeviceInfo() {
return deviceInfo;
}
public void setDeviceInfo(String deviceInfo) {
this.deviceInfo = deviceInfo;
}
public String getTradeType() {
return tradeType;
}
public void setTradeType(String tradeType) {
this.tradeType = tradeType;
}
public String getNotifyUrl() {
return notifyUrl;
}
public void setNotifyUrl(String notifyUrl) {
this.notifyUrl = notifyUrl;
}
public String getSpbillCreateIp() {
return spbillCreateIp;
}
public void setSpbillCreateIp(String spbillCreateIp) {
this.spbillCreateIp = spbillCreateIp;
}
public String getPrivateKey() {
return privateKey;
}
public void setPrivateKey(String privateKey) {
this.privateKey = privateKey;
}
public String getSecurityCertificate() {
return securityCertificate;
}
public void setSecurityCertificate(String securityCertificate) {
this.securityCertificate = securityCertificate;
}
public String getRefundAccount() {
return refundAccount;
}
public void setRefundAccount(String refundAccount) {
this.refundAccount = refundAccount;
}