search
HomeWeChat AppletWeChat DevelopmentShare front-end WeChat payment js code

Share front-end WeChat payment js code

Mar 28, 2017 pm 01:57 PM
WeChat Pay

The example in this article shares the front-end WeChat paymentjs code for your reference. The specific content is as follows

$('.Save_Patient_Msg').click(function(){
 $('.Save_Patient_Msg').off('click');
 var hrdfId = getOrderId();
 var txnAmt = $('.sum_pay.font-red').html(); 
  
 var data = {orderId: hrdfId, txnAmt: "0.01", 
 prodDesc: "远程诊断服务", callType: "JSAPI",
 access_token: getUrlParam("access_token")
 };
  
 $.ajax({
 type: 'POST',
 url: '/hims/api/commonPay/queryTransNo?access_token='+getUrlParam('access_token'),
 dataType:'json',
 contentType:'application/json',
 data: JSON.stringify(data),
 success: function(Wxres){
 if(!Wxres){
 $.alert('服务器拥堵,请稍后访问')
 }else{
  console.log(Wxres);
  if(Wxres.data.respCode == 'fail'){
  $.alert(Wxres.data.respMsg);
  }else{
  //10 微信支付接口
  // 10.1 发起一个支付请求
  // 注意:此 Demo 使用 2.7 版本支付接口实现,建议使用此接口时参考微信支付相关最新文档。
  var param = Wxres.data;
  wx.config({
  debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  appId: 'wx403ead26691402fb', // 必填,公众号的唯一标识
  timestamp: param.timestamp, // 必填,生成签名的时间戳
  nonceStr: param.noncestr, // 必填,生成签名的随机串
  signature: param.signJs,// 必填,调用js签名,
  jsApiList: ['chooseWXPay'] // 必填,需要使用的JS接口列表,这里只写支付的
  });
  wx.chooseWXPay({
  timestamp: param.timestamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  nonceStr: param.noncestr, // 支付签名随机串,不长于 32 位
  package: "prepay_id="+param.transNo, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***)
  signType: "MD5", // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
  paySign: param.sign, // 支付签名
  success: function (res) {
  if(res.errMsg == "chooseWXPay:ok"){
   //alert("支付成功");
   window.location.href = "/hims/weixin/pages/Order_ok.html?access_token="+getUrlParam("access_token");
  }else{
   alert(res.errMsg);
  }
  },
  cancel: function(res){
  //alert('取消支付');
  }
  });
  }
   
 } 
 },
 error:function(data){
  var msg = data.message || data.status;
  $.alert('服务器错误'+msg);
 }
 }); 
 return false;
  
 });
  
 function getUrlParam(name){
 var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
 var r = window.location.search.substr(1).match(reg); //匹配目标参数
 if (r!=null) return unescape(r[2]); return null; //返回参数值
 } 
  
 })

The above is the detailed content of Share front-end WeChat payment js code. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use