# 微信公众号JSSDK
官方[https://mp.weixin.qq.com/wikit=resource/res\_main&id=mp1421141115](https://mp.weixin.qq.com/wikit=resource/res_main&id=mp1421141115)
文件<https://res.wx.qq.com/open/js/jweixin-1.4.0.js>
### 分享自定义
```
<pre class="calibre14">```
<span class="token2">{</span>php echo <span class="token1">register_jssdk</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span><span class="token2">}</span>
<span class="token"><</span>script<span class="token">></span>
wx<span class="token2">.</span><span class="token1">ready</span><span class="token2">(</span><span class="token5">function</span> <span class="token2">(</span><span class="token2">)</span> <span class="token2">{</span>
sharedata <span class="token">=</span> <span class="token2">{</span>
title<span class="token2">:</span> <span class="token4">'微信JS-SDK Demo'</span><span class="token2">,</span>
desc<span class="token2">:</span> <span class="token4">'微信JS-SDK,帮助第三方为用户提供更优质的移动web服务'</span><span class="token2">,</span>
link<span class="token2">:</span> jssdkconfig<span class="token2">.</span>url<span class="token2">,</span>
imgUrl<span class="token2">:</span> <span class="token4">'http://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRt8Qia4lv7k3M9J1SKqKCImxJCt7j9rHYicKDI45jRPBxdzdyREWnk0ia0N5TMnMfth7SdxtzMvVgXg/0'</span><span class="token2">,</span>
success<span class="token2">:</span> <span class="token5">function</span><span class="token2">(</span><span class="token2">)</span><span class="token2">{</span>
<span class="token1">alert</span><span class="token2">(</span><span class="token4">'success'</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span><span class="token2">,</span>
cancel<span class="token2">:</span> <span class="token5">function</span><span class="token2">(</span><span class="token2">)</span><span class="token2">{</span>
<span class="token1">alert</span><span class="token2">(</span><span class="token4">'cancel'</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
<span class="token2">}</span><span class="token2">;</span>
wx<span class="token2">.</span><span class="token1">hideOptionMenu</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>
wx<span class="token2">.</span><span class="token1">showMenuItems</span><span class="token2">(</span><span class="token2">{</span>
menuList<span class="token2">:</span> <span class="token2">[</span>
<span class="token4">'menuItem:share:timeline'</span><span class="token2">,</span>
<span class="token4">'menuItem:share:appMessage'</span><span class="token2">,</span>
<span class="token4">'menuItem:copyUrl'</span><span class="token2">,</span>
<span class="token4">'menuItem:favorite'</span><span class="token2">,</span>
<span class="token4">'menuItem:openWithSafari'</span><span class="token2">,</span>
<span class="token4">'menuItem:openWithQQBrowser'</span>
<span class="token2">]</span><span class="token2">,</span>
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
wx<span class="token2">.</span><span class="token1">onMenuShareAppMessage</span><span class="token2">(</span>sharedata<span class="token2">)</span><span class="token2">;</span>
wx<span class="token2">.</span><span class="token1">onMenuShareTimeline</span><span class="token2">(</span>sharedata<span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
收货地址共享jssdk<span class="token">></span><span class="token3">1.2</span>
wx<span class="token2">.</span><span class="token1">openAddress</span><span class="token2">(</span><span class="token2">{</span>
success <span class="token2">:</span> <span class="token5">function</span><span class="token2">(</span>res<span class="token2">)</span><span class="token2">{</span>
<span class="token1">alert</span><span class="token2">(</span>JSON<span class="token2">.</span><span class="token1">stringify</span><span class="token2">(</span>res<span class="token2">)</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span><span class="token2">,</span>cancel<span class="token2">:</span> <span class="token5">function</span> <span class="token2">(</span><span class="token2">)</span> <span class="token2">{</span>
<span class="token1">alert</span><span class="token2">(</span><span class="token4">"取消了"</span><span class="token2">)</span><span class="token2">;</span><span class="token2">}</span>
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
<span class="token"><</span><span class="token">/</span>script<span class="token">></span>
```
```
```
<pre class="calibre14">```
$wx <span class="token">=</span> $_W<span class="token2">[</span><span class="token4">'account'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'jssdkconfig'</span><span class="token2">]</span><span class="token2">;</span>
```
```
关闭当前页,无需签名
```
<pre class="calibre14">```
document<span class="token2">.</span><span class="token1">addEventListener</span><span class="token2">(</span><span class="token4">"WeixinJSBridgeReady"</span><span class="token2">,</span> <span class="token5">function</span> <span class="token1">onBridgeReady</span><span class="token2">(</span><span class="token2">)</span> <span class="token2">{</span>
WeixinJSBridge<span class="token2">.</span><span class="token1">call</span><span class="token2">(</span><span class="token4">"closeWindow"</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
a 标签等 直接用 WeixinJSBridge<span class="token2">.</span><span class="token1">call</span><span class="token2">(</span><span class="token4">"closeWindow"</span><span class="token2">)</span><span class="token2">;</span>
```
```
支付的调用
```
<pre class="calibre14">```
$<span class="token2">.</span><span class="token1">post</span><span class="token2">(</span><span class="token4">"{$payurl}"</span><span class="token2">,</span><span class="token2">{</span><span class="token2">}</span><span class="token2">,</span> <span class="token5">function</span><span class="token2">(</span>data<span class="token2">)</span><span class="token2">{</span><span class="token6">//发送到下单接口</span>
data <span class="token">=</span> JSON<span class="token2">.</span><span class="token1">parse</span><span class="token2">(</span>data<span class="token2">)</span><span class="token2">;</span><span class="token6">//获取json数据</span>
WeixinJSBridge<span class="token2">.</span><span class="token1">invoke</span><span class="token2">(</span><span class="token4">'getBrandWCPayRequest'</span><span class="token2">,</span> <span class="token2">{</span>
<span class="token4">'appId'</span> <span class="token2">:</span> data<span class="token2">.</span>appId<span class="token2">,</span>
<span class="token4">'timeStamp'</span><span class="token2">:</span> data<span class="token2">.</span>timeStamp<span class="token2">,</span>
<span class="token4">'nonceStr'</span> <span class="token2">:</span> data<span class="token2">.</span>nonceStr<span class="token2">,</span>
<span class="token4">'package'</span> <span class="token2">:</span> data<span class="token2">.</span>package<span class="token2">,</span>
<span class="token4">'signType'</span> <span class="token2">:</span> data<span class="token2">.</span>signType<span class="token2">,</span>
<span class="token4">'paySign'</span> <span class="token2">:</span> data<span class="token2">.</span>paySign
<span class="token2">}</span><span class="token2">,</span> <span class="token5">function</span><span class="token2">(</span>res<span class="token2">)</span> <span class="token2">{</span>
<span class="token5">if</span><span class="token2">(</span>res<span class="token2">.</span>err_msg <span class="token">==</span> <span class="token4">'get_brand_wcpay_request:ok'</span><span class="token2">)</span> <span class="token2">{</span>
<span class="token1">alert</span><span class="token2">(</span><span class="token4">'成功支付'</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span> <span class="token5">else</span> <span class="token5">if</span><span class="token2">(</span>res<span class="token2">.</span>err_msg <span class="token">==</span> <span class="token4">'get_brand_wcpay_request:cancel'</span><span class="token2">)</span><span class="token2">{</span>
<span class="token1">alert</span><span class="token2">(</span><span class="token4">'支付取消'</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span><span class="token5">else</span><span class="token2">{</span>
<span class="token1">alert</span><span class="token2">(</span><span class="token4">"error code:"</span><span class="token">+</span>res<span class="token2">.</span>err_msg<span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
```
```
图片浏览,只需要图片加上 weixin 类即可
```
<pre class="calibre14">```
var weixinimg<span class="token">=</span><span class="token2">[</span><span class="token2">]</span><span class="token2">;</span>
var weixinsrc<span class="token">=</span><span class="token2">[</span><span class="token2">]</span><span class="token2">;</span>
weixinimg<span class="token">=</span>$<span class="token2">(</span><span class="token4">'.weixin'</span><span class="token2">)</span><span class="token2">;</span>
<span class="token5">for</span> <span class="token2">(</span>var i<span class="token">=</span><span class="token3">0</span><span class="token2">;</span>i<span class="token"><</span>weixinimg<span class="token2">.</span>length<span class="token2">;</span>i<span class="token">++</span><span class="token2">)</span><span class="token2">{</span>
weixinsrc<span class="token2">[</span>i<span class="token2">]</span><span class="token">=</span>weixinimg<span class="token2">[</span>i<span class="token2">]</span><span class="token2">.</span>src<span class="token2">;</span>
<span class="token2">}</span>
$<span class="token2">(</span><span class="token4">'.weixin'</span><span class="token2">)</span><span class="token2">.</span><span class="token1">click</span><span class="token2">(</span><span class="token5">function</span><span class="token2">(</span><span class="token2">)</span><span class="token2">{</span>
var index <span class="token">=</span> $<span class="token2">(</span><span class="token4">'.weixin'</span><span class="token2">)</span><span class="token2">.</span><span class="token1">index</span><span class="token2">(</span>this<span class="token2">)</span><span class="token2">;</span>
wx<span class="token2">.</span><span class="token1">previewImage</span><span class="token2">(</span><span class="token2">{</span>
current<span class="token2">:</span> weixinsrc<span class="token2">[</span>index<span class="token2">]</span><span class="token2">,</span>
urls<span class="token2">:</span>weixinsrc
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
```
```
单多图上传
```
<pre class="calibre14">```
<span class="token6">//单图上传</span>
$<span class="token2">(</span><span class="token4">'#i1'</span><span class="token2">)</span><span class="token2">.</span><span class="token1">on</span><span class="token2">(</span><span class="token4">'click'</span><span class="token2">,</span> <span class="token5">function</span> <span class="token2">(</span><span class="token2">)</span> <span class="token2">{</span>
wx<span class="token2">.</span><span class="token1">chooseImage</span><span class="token2">(</span><span class="token2">{</span>
count<span class="token2">:</span><span class="token3">1</span><span class="token2">,</span>
success<span class="token2">:</span> <span class="token5">function</span> <span class="token2">(</span>res<span class="token2">)</span> <span class="token2">{</span>
var localIds <span class="token">=</span> res<span class="token2">.</span>localIds<span class="token2">;</span>
<span class="token1">syncUpload1</span><span class="token2">(</span>localIds<span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
var syncUpload1 <span class="token">=</span> <span class="token5">function</span><span class="token2">(</span>localIds<span class="token2">)</span><span class="token2">{</span>
var localId <span class="token">=</span> localIds<span class="token2">.</span><span class="token1">pop</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>
wx<span class="token2">.</span><span class="token1">uploadImage</span><span class="token2">(</span><span class="token2">{</span>
localId<span class="token2">:</span> localId<span class="token2">,</span>
isShowProgressTips<span class="token2">:</span> <span class="token3">1</span><span class="token2">,</span>
success<span class="token2">:</span> <span class="token5">function</span> <span class="token2">(</span>res<span class="token2">)</span> <span class="token2">{</span>
var serverId <span class="token">=</span> res<span class="token2">.</span>serverId<span class="token2">;</span> <span class="token6">// 返回图片的服务器端ID</span>
$<span class="token2">.</span><span class="token1">post</span><span class="token2">(</span><span class="token4">"{$_W['siteroot']}app/index.php?i={$weid}&c=entry&do=ajax1&m=we7_demo"</span><span class="token2">,</span><span class="token2">{</span>mid<span class="token2">:</span>serverId<span class="token2">}</span><span class="token2">,</span><span class="token5">function</span><span class="token2">(</span>data<span class="token2">)</span><span class="token2">{</span>
$<span class="token2">(</span><span class="token4">'#img1'</span><span class="token2">)</span><span class="token2">.</span><span class="token1">html</span><span class="token2">(</span><span class="token4">'<li class="weui_uploader_file" style="background-image:url('</span><span class="token">+</span>data<span class="token2">.</span>src<span class="token">+</span><span class="token4">')"></li>'</span><span class="token2">)</span><span class="token2">;</span>
$<span class="token2">(</span><span class="token4">'#imgi'</span><span class="token2">)</span><span class="token2">.</span><span class="token1">html</span><span class="token2">(</span><span class="token4">'<input value="'</span><span class="token">+</span>data<span class="token2">.</span>src<span class="token">+</span><span class="token4">'" type="hidden" name="files" />'</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span><span class="token2">,</span><span class="token4">'json'</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span><span class="token2">;</span>
<span class="token6">//多图上传</span>
$<span class="token2">(</span><span class="token4">'#headimgurl2'</span><span class="token2">)</span><span class="token2">.</span><span class="token1">on</span><span class="token2">(</span><span class="token4">'click'</span><span class="token2">,</span> <span class="token5">function</span> <span class="token2">(</span><span class="token2">)</span> <span class="token2">{</span>
wx<span class="token2">.</span><span class="token1">chooseImage</span><span class="token2">(</span><span class="token2">{</span>
success<span class="token2">:</span> <span class="token5">function</span> <span class="token2">(</span>res<span class="token2">)</span> <span class="token2">{</span>
var localIds <span class="token">=</span> res<span class="token2">.</span>localIds<span class="token2">;</span>
<span class="token1">syncUpload</span><span class="token2">(</span>localIds<span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
var syncUpload <span class="token">=</span> <span class="token5">function</span><span class="token2">(</span>localIds<span class="token2">)</span><span class="token2">{</span>
var localId <span class="token">=</span> localIds<span class="token2">.</span><span class="token1">pop</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>
wx<span class="token2">.</span><span class="token1">uploadImage</span><span class="token2">(</span><span class="token2">{</span>
localId<span class="token2">:</span> localId<span class="token2">,</span>
isShowProgressTips<span class="token2">:</span> <span class="token3">1</span><span class="token2">,</span>
success<span class="token2">:</span> <span class="token5">function</span> <span class="token2">(</span>res<span class="token2">)</span> <span class="token2">{</span>
var serverId <span class="token">=</span> res<span class="token2">.</span>serverId<span class="token2">;</span> <span class="token6">// 返回图片的服务器端ID</span>
$<span class="token2">.</span><span class="token1">post</span><span class="token2">(</span><span class="token4">"{$_W['siteroot']}app/index.php?i={$weid}&c=entry&do=ajax1&m=we7_demo"</span><span class="token2">,</span><span class="token2">{</span>mid<span class="token2">:</span>serverId<span class="token2">}</span><span class="token2">,</span><span class="token5">function</span><span class="token2">(</span>data<span class="token2">)</span><span class="token2">{</span>
$<span class="token2">(</span><span class="token4">'#img2'</span><span class="token2">)</span><span class="token2">.</span><span class="token1">append</span><span class="token2">(</span><span class="token4">'<li class="weui_uploader_file" style="background-image:url('</span><span class="token">+</span>data<span class="token2">.</span>src<span class="token">+</span><span class="token4">')"></li>'</span><span class="token2">)</span><span class="token2">;</span>
$<span class="token2">(</span><span class="token4">'#file2'</span><span class="token2">)</span><span class="token2">.</span><span class="token1">append</span><span class="token2">(</span><span class="token4">'<input value="'</span><span class="token">+</span>data<span class="token2">.</span>src<span class="token">+</span><span class="token4">'" type="hidden" name="files[]" />'</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span><span class="token2">,</span><span class="token4">'json'</span><span class="token2">)</span><span class="token2">;</span>
<span class="token5">if</span><span class="token2">(</span>localIds<span class="token2">.</span>length <span class="token">></span> <span class="token3">0</span><span class="token2">)</span><span class="token2">{</span>
<span class="token1">syncUpload</span><span class="token2">(</span>localIds<span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
<span class="token2">}</span>
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span><span class="token2">;</span>
```
```
扫码
```
<pre class="calibre14">```
document<span class="token2">.</span><span class="token1">querySelector</span><span class="token2">(</span><span class="token4">'#qr'</span><span class="token2">)</span><span class="token2">.</span>onclick <span class="token">=</span> <span class="token5">function</span> <span class="token2">(</span><span class="token2">)</span> <span class="token2">{</span>
wx<span class="token2">.</span><span class="token1">scanQRCode</span><span class="token2">(</span><span class="token2">{</span>
needResult<span class="token2">:</span> <span class="token3">1</span><span class="token2">,</span><span class="token6">//0是微信处理,1是结果</span>
desc<span class="token2">:</span> <span class="token4">'我们自己来处理结果'</span><span class="token2">,</span>
scanType<span class="token2">:</span> <span class="token2">[</span><span class="token4">"qrCode"</span><span class="token2">,</span><span class="token4">"barCode"</span><span class="token2">]</span><span class="token2">,</span>
success<span class="token2">:</span> <span class="token5">function</span> <span class="token2">(</span>res<span class="token2">)</span> <span class="token2">{</span>
var result <span class="token">=</span> res<span class="token2">.</span>resultStr<span class="token2">;</span>
$<span class="token2">.</span><span class="token1">alert</span><span class="token2">(</span>result<span class="token2">,</span><span class="token4">"扫描结果"</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span><span class="token2">;</span>
```
```
自动获取地理位置,需要腾讯地图蜜月
```
<pre class="calibre14">```
wx<span class="token2">.</span><span class="token1">getLocation</span><span class="token2">(</span><span class="token2">{</span>
type<span class="token2">:</span> <span class="token4">'wgs84'</span><span class="token2">,</span> <span class="token6">// 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'</span>
success<span class="token2">:</span> <span class="token5">function</span> <span class="token2">(</span>res<span class="token2">)</span> <span class="token2">{</span>
var latitude <span class="token">=</span> res<span class="token2">.</span>latitude<span class="token2">;</span> <span class="token6">// 纬度,浮点数,范围为90 ~ -90</span>
var longitude <span class="token">=</span> res<span class="token2">.</span>longitude<span class="token2">;</span> <span class="token6">// 经度,浮点数,范围为180 ~ -180。</span>
var speed <span class="token">=</span> res<span class="token2">.</span>speed<span class="token2">;</span> <span class="token6">// 速度,以米/每秒计</span>
var accuracy <span class="token">=</span> res<span class="token2">.</span>accuracy<span class="token2">;</span> <span class="token6">// 位置精度</span>
<span class="token6">//alert(JSON.stringify(res));</span>
$<span class="token2">.</span><span class="token1">get</span><span class="token2">(</span><span class="token4">"http://apis.map.qq.com/ws/geocoder/v1/?location="</span><span class="token">+</span>latitude<span class="token">+</span><span class="token4">","</span><span class="token">+</span>longitude<span class="token">+</span><span class="token4">"&key={$mapkey}&get_poi=0&output=jsonp&callback=?"</span><span class="token2">,</span><span class="token5">function</span><span class="token2">(</span>data<span class="token2">)</span> <span class="token2">{</span>
console<span class="token2">.</span><span class="token1">log</span><span class="token2">(</span>data<span class="token2">)</span><span class="token2">;</span>
<span class="token5">if</span><span class="token2">(</span>data<span class="token2">.</span>status<span class="token">==</span><span class="token3">0</span><span class="token2">)</span><span class="token2">{</span>
var province <span class="token">=</span> data<span class="token2">.</span>result<span class="token2">.</span>address_component<span class="token2">.</span>province<span class="token2">;</span>
province <span class="token">=</span> <span class="token1">preg_replace</span><span class="token2">(</span><span class="token4">'/市/'</span><span class="token2">,</span><span class="token4">""</span><span class="token2">,</span>province<span class="token2">)</span><span class="token2">;</span>
province <span class="token">=</span> <span class="token1">preg_replace</span><span class="token2">(</span><span class="token4">'/省/'</span><span class="token2">,</span><span class="token4">""</span><span class="token2">,</span>province<span class="token2">)</span><span class="token2">;</span>
var city <span class="token">=</span> data<span class="token2">.</span>result<span class="token2">.</span>address_component<span class="token2">.</span>city<span class="token2">;</span>
city <span class="token">=</span> <span class="token1">preg_replace</span><span class="token2">(</span><span class="token4">'/市/'</span><span class="token2">,</span><span class="token4">""</span><span class="token2">,</span>city<span class="token2">)</span><span class="token2">;</span>
var qu <span class="token">=</span> data<span class="token2">.</span>result<span class="token2">.</span>address_component<span class="token2">.</span>district<span class="token2">;</span>
$<span class="token2">(</span><span class="token4">"#address1"</span><span class="token2">)</span><span class="token2">.</span><span class="token1">val</span><span class="token2">(</span>province<span class="token">+</span><span class="token4">" "</span><span class="token">+</span>city<span class="token">+</span><span class="token4">" "</span><span class="token">+</span>qu<span class="token2">)</span><span class="token2">;</span>
$<span class="token2">(</span><span class="token4">"#address2"</span><span class="token2">)</span><span class="token2">.</span><span class="token1">val</span><span class="token2">(</span>province<span class="token">+</span><span class="token4">" "</span><span class="token">+</span>city<span class="token">+</span><span class="token4">" "</span><span class="token">+</span>qu<span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
<span class="token2">}</span><span class="token2">,</span><span class="token4">'jsonp'</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
```
```
查看位置
```
<pre class="calibre14">```
wx<span class="token2">.</span><span class="token1">openLocation</span><span class="token2">(</span><span class="token2">{</span>
latitude<span class="token2">:</span> <span class="token3">23.099994</span><span class="token2">,</span><span class="token6">//纬度</span>
longitude<span class="token2">:</span> <span class="token3">113.324520</span><span class="token2">,</span><span class="token6">//经度</span>
name<span class="token2">:</span> <span class="token4">'TIT 创意园'</span><span class="token2">,</span><span class="token6">//名称</span>
address<span class="token2">:</span> <span class="token4">'广州市海珠区新港中路 397 号'</span><span class="token2">,</span>
scale<span class="token2">:</span> <span class="token3">14</span><span class="token2">,</span><span class="token6">//缩放等级1-28 默认1最大</span>
infoUrl<span class="token2">:</span> <span class="token4">'http://weixin.qq.com'</span><span class="token2">,</span><span class="token6">//详细信息</span>
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
```
```
显示 影藏 关闭
```
<pre class="calibre14">```
wx<span class="token2">.</span><span class="token1">ready</span><span class="token2">(</span><span class="token5">function</span> <span class="token2">(</span><span class="token2">)</span> <span class="token2">{</span>
wx<span class="token2">.</span><span class="token1">hideOptionMenu</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span><span class="token2">)</span>
wx<span class="token2">.</span><span class="token1">ready</span><span class="token2">(</span><span class="token5">function</span> <span class="token2">(</span><span class="token2">)</span> <span class="token2">{</span>
wx<span class="token2">.</span><span class="token1">showOptionMenu</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span><span class="token2">)</span>
wx<span class="token2">.</span><span class="token1">ready</span><span class="token2">(</span><span class="token5">function</span> <span class="token2">(</span><span class="token2">)</span> <span class="token2">{</span>
wx<span class="token2">.</span><span class="token1">closeWindow</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span><span class="token2">)</span>
```
```
阻止滑动
```
<pre class="calibre14">```
<span class="token5">function</span> <span class="token1">stopDrop</span><span class="token2">(</span><span class="token2">)</span> <span class="token2">{</span>
var c<span class="token2">;</span>
$<span class="token2">(</span>document<span class="token2">.</span>body<span class="token2">)</span><span class="token2">.</span><span class="token1">on</span><span class="token2">(</span><span class="token4">'touchstart'</span><span class="token2">,</span> <span class="token5">function</span><span class="token2">(</span>a<span class="token2">)</span> <span class="token2">{</span>
c <span class="token">=</span> a<span class="token2">.</span>originalEvent<span class="token2">.</span>changedTouches<span class="token2">[</span><span class="token3">0</span><span class="token2">]</span><span class="token2">.</span>clientY
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
$<span class="token2">(</span>document<span class="token2">.</span>body<span class="token2">)</span><span class="token2">.</span><span class="token1">on</span><span class="token2">(</span><span class="token4">'touchmove'</span><span class="token2">,</span> <span class="token5">function</span><span class="token2">(</span>a<span class="token2">)</span> <span class="token2">{</span>
var y <span class="token">=</span> a<span class="token2">.</span>originalEvent<span class="token2">.</span>changedTouches<span class="token2">[</span><span class="token3">0</span><span class="token2">]</span><span class="token2">.</span>clientY<span class="token2">;</span>
var b <span class="token">=</span> $<span class="token2">(</span>this<span class="token2">)</span><span class="token2">.</span><span class="token1">scrollTop</span><span class="token2">(</span><span class="token2">)</span>
<span class="token2">}</span><span class="token2">)</span><span class="token2">;</span>
$<span class="token2">(</span>document<span class="token2">.</span>body<span class="token2">)</span><span class="token2">.</span><span class="token1">on</span><span class="token2">(</span><span class="token4">'touchend'</span><span class="token2">,</span> <span class="token5">function</span><span class="token2">(</span>a<span class="token2">)</span> <span class="token2">{</span>
c <span class="token">=</span> a<span class="token2">.</span>originalEvent<span class="token2">.</span>changedTouches<span class="token2">[</span><span class="token3">0</span><span class="token2">]</span><span class="token2">.</span>clientY<span class="token2">;</span>
$<span class="token2">(</span>this<span class="token2">)</span><span class="token2">.</span><span class="token1">scrollTop</span><span class="token2">(</span><span class="token3">0</span><span class="token2">)</span>
<span class="token2">}</span><span class="token2">)</span>
<span class="token2">}</span>
<span class="token1">stopDrop</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>
```
```
下单1分钱返回
```
<pre class="calibre14">```
Array
<span class="token2">(</span>
<span class="token2">[</span>appid<span class="token2">]</span> <span class="token">=</span><span class="token">></span> wx001
<span class="token2">[</span>attach<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">1</span>
<span class="token2">[</span>bank_type<span class="token2">]</span> <span class="token">=</span><span class="token">></span> CFT
<span class="token2">[</span>cash_fee<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">1</span>
<span class="token2">[</span>fee_type<span class="token2">]</span> <span class="token">=</span><span class="token">></span> CNY
<span class="token2">[</span>is_subscribe<span class="token2">]</span> <span class="token">=</span><span class="token">></span> Y
<span class="token2">[</span>mch_id<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">111</span>
<span class="token2">[</span>nonce_str<span class="token2">]</span> <span class="token">=</span><span class="token">></span> IgtZ3c0g
<span class="token2">[</span>openid<span class="token2">]</span> <span class="token">=</span><span class="token">></span> oN44zxCvQlYaAoEFU3UDa0uiysqA
<span class="token2">[</span>out_trade_no<span class="token2">]</span> <span class="token">=</span><span class="token">></span> YO20180128022645129464
<span class="token2">[</span>result_code<span class="token2">]</span> <span class="token">=</span><span class="token">></span> SUCCESS
<span class="token2">[</span>return_code<span class="token2">]</span> <span class="token">=</span><span class="token">></span> SUCCESS
<span class="token2">[</span>sign<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">7</span>C604C785ED4119FC60FB23C97E76EC4
<span class="token2">[</span>time_end<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">20180128022652</span>
<span class="token2">[</span>total_fee<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">1</span>
<span class="token2">[</span>trade_type<span class="token2">]</span> <span class="token">=</span><span class="token">></span> JSAPI
<span class="token2">[</span>transaction_id<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">4200000100201801282214387872</span>
<span class="token2">)</span>
```
```
支付成功通知返回
```
<pre class="calibre14">```
Array
<span class="token2">(</span>
<span class="token2">[</span>card_fee<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">0.01</span>
<span class="token2">[</span>card_id<span class="token2">]</span> <span class="token">=</span><span class="token">></span>
<span class="token2">[</span>card_type<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">0</span>
<span class="token2">[</span>fee<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">0.01</span>
<span class="token2">[</span>from<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token5">return</span>
<span class="token2">[</span>is_usecard<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">0</span>
<span class="token2">[</span>result<span class="token2">]</span> <span class="token">=</span><span class="token">></span> success
<span class="token2">[</span>tag<span class="token2">]</span> <span class="token">=</span><span class="token">></span> Array
<span class="token2">(</span>
<span class="token2">[</span>acid<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">1</span>
<span class="token2">[</span>uid<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">1</span>
<span class="token2">[</span>transaction_id<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">4200000084201801282604370765</span>
<span class="token2">)</span>
<span class="token2">[</span>tid<span class="token2">]</span> <span class="token">=</span><span class="token">></span> YO20180128222321512481
<span class="token2">[</span>type<span class="token2">]</span> <span class="token">=</span><span class="token">></span> wechat
<span class="token2">[</span>uniacid<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">1</span>
<span class="token2">[</span>uniontid<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">2018012822232100005314224341</span>
<span class="token2">[</span>user<span class="token2">]</span> <span class="token">=</span><span class="token">></span> oN44zxCvQlYaAoEFU3UDa0uiysqA
<span class="token2">[</span>weid<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">1</span>
<span class="token2">)</span>
```
```
支付注意
```
<pre class="calibre16">```
支付成功处理方法<span class="token2">,</span>需要注意<span class="token2">,</span>在此方法内获取不到$_W值<span class="token2">,</span>以及使用借用后参数配置也是借用公众号的<span class="token2">,</span>
public <span class="token5">function</span> <span class="token1">payResult</span><span class="token2">(</span>$params<span class="token2">)</span> <span class="token2">{</span><span class="token6">//支付成功处理 </span>
<span class="token5">if</span> <span class="token2">(</span>$params<span class="token2">[</span><span class="token4">'result'</span><span class="token2">]</span> <span class="token">==</span> <span class="token4">'success'</span> <span class="token">&&</span> $params<span class="token2">[</span><span class="token4">'from'</span><span class="token2">]</span> <span class="token">==</span> <span class="token4">'notify'</span><span class="token2">)</span> <span class="token2">{</span>
$setting <span class="token">=</span> <span class="token1">pdo_get</span><span class="token2">(</span><span class="token4">'uni_account_modules'</span><span class="token2">,</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">'module'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'yoby_che'</span><span class="token2">,</span> <span class="token4">'uniacid'</span> <span class="token">=</span><span class="token">></span> $params<span class="token2">[</span><span class="token4">'uniacid'</span><span class="token2">]</span><span class="token2">)</span><span class="token2">)</span><span class="token2">;</span>
$arr <span class="token">=</span> <span class="token1">iunserializer</span><span class="token2">(</span>$setting<span class="token2">[</span><span class="token4">'settings'</span><span class="token2">]</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
<span class="token5">if</span> <span class="token2">(</span>$params<span class="token2">[</span><span class="token4">'from'</span><span class="token2">]</span> <span class="token">==</span> <span class="token4">'return'</span><span class="token2">)</span> <span class="token2">{</span>
<span class="token5">if</span> <span class="token2">(</span>$params<span class="token2">[</span><span class="token4">'result'</span><span class="token2">]</span> <span class="token">==</span> <span class="token4">'success'</span><span class="token2">)</span> <span class="token2">{</span>
<span class="token1">message</span><span class="token2">(</span><span class="token4">'支付成功!'</span><span class="token2">,</span><span class="token1">murl</span><span class="token2">(</span><span class="token4">'entry'</span><span class="token2">,</span> <span class="token2">[</span><span class="token4">'m'</span><span class="token">=</span><span class="token">></span><span class="token4">'yoby_che'</span><span class="token2">,</span><span class="token4">'do'</span><span class="token">=</span><span class="token">></span><span class="token4">'vpay'</span><span class="token2">]</span><span class="token2">,</span> <span class="token3">1</span><span class="token2">,</span><span class="token3">1</span><span class="token2">)</span><span class="token2">,</span> <span class="token4">'success'</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span> <span class="token5">else</span> <span class="token2">{</span>
<span class="token1">message</span><span class="token2">(</span><span class="token4">'支付失败!'</span><span class="token2">,</span><span class="token1">murl</span><span class="token2">(</span><span class="token4">'entry'</span><span class="token2">,</span> <span class="token2">[</span><span class="token4">'m'</span><span class="token">=</span><span class="token">></span><span class="token4">'yoby_che'</span><span class="token2">,</span><span class="token4">'do'</span><span class="token">=</span><span class="token">></span><span class="token4">'fm'</span><span class="token2">]</span><span class="token2">,</span> <span class="token3">1</span><span class="token2">,</span><span class="token3">1</span><span class="token2">)</span><span class="token2">,</span> <span class="token4">'error'</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
<span class="token2">}</span>
```
```
- 简介
- 第一章 数据库
- Mysql/mariadb
- 函数
- 基础
- 增删改索引
- 标准查询
- 高级查询
- TIDB集群mysql解决方案
- Redis
- 语言基础
- 5种数据类型
- 其他类型
- Sqlite
- 语言基础
- 常用查询
- 第二章 PHP
- 语言基础
- 第一课 流程控制和运算
- 第二课 数组
- 第三课 日期时间
- 第四课 常用函数
- 第五课 字符串
- 第六课 文件操作
- 第七课 面向对象
- 第八课 正则表达式
- 第九课 图片处理生成
- 第十课 curl/memche
- 第十一课 mysql和pdo
- 第十三课 cookie和session
- 第十四课 xml操作
- 第十五课 php5.3+新特性
- 第十六课 php7+
- 第十七课 密码安全
- 废弃函数
- php命令行
- redis应用
- 算法
- 排序算法
- 基础算法
- 无限级分类
- 自定义函数Fn
- 查找算法
- 自定义函数数据函数fn
- laravel
- 路由
- 常用语句
- 数据库
- dingo/api
- Yii2
- 控制器
- 常用类
- 数据库
- redis
- thinkphp6
- TP6文档
- TP6插件
- dedecms
- 织梦标签大全
- 数据库操作
- 内置函数和定义函数
- 织梦核心改动
- 织梦插件/底层标签开发
- PHP相关工具
- composer
- php开发环境phpenv
- Phpstorm使用
- windows编译php扩展
- PHP开源库
- 开源项目管理禅道
- sns_auth
- php-casbin权限控制
- php-jwt
- 微信SDKeasywechat
- querylist采集库
- workerman
- Box/Spout处理excel和csv
- dll扩展
- redis/memche/xdebug
- redis
- Lua
- php_xlswriter
- event
- swoole
- 常用代码库
- 微擎框架
- 第一课全局变量
- 第二课常用函数
- 第三课自定义微擎独有函数
- 第四课数据库操作
- 第五课微信端回复
- 第六课微擎高级操作
- 第八课global函数列表
- mainfest.xml详解
- js方法
- 人人商城
- 第一课model解读
- 第二课常用语句解读
- 第三课常用js解读
- 第四课附录常见问题
- 第五课附录处理报表|支付
- 常用JSON状态码
- 第三章 JavaScript
- js基础
- 浏览器对象
- 语言基础
- html5接口
- ES6新语法
- vue
- 基础语法
- 京东vueUI组件
- uniapp
- 组件开发规范
- nodejs
- 基础知识
- 安装node
- nvm不同版本node切换
- js常用标准库
- zepto/jquery
- weui
- js图标库
- elementUI
- validator表单验证
- layer弹出层
- requirejs
- wow动画
- 动画animate
- swiper4
- 百度编辑器
- flyio/axios/qs
- jquery.form
- bootstrap3
- clipboard复制
- slideout侧滑
- imagehover.css图片悬停动画
- webpack打包
- Bulma UI框架
- store 客户端存储
- lottie动画创建库
- sweetalert
- js自定义函数
- 常见JSSDK
- 微信公众号JSSDK
- 腾讯地图jssdk
- 微信小程序
- 第四章 编程语言
- markdown语言
- Dart语言
- Dart语言基础
- Flutter框架
- Lua语言
- 字符串,数组,表
- 自定义方法
- go语言
- 第1.1语言基本语法
- 第1.2流程控制
- 第1.3函数
- 第1.4结构体
- 第1.5接口
- 第1.6包
- go语言框架Gin
- CSS3语言
- CSS与CSS3
- 选择符
- 属性
- css3
- loading动画
- HTML5语言
- less
- sass
- C#
- 基础知识
- 函数
- 第五章 开发工具
- git
- nginx/apache服务器
- Linux常用操作
- crontab定时任务
- 注册表与cmd
- 阿里云ECS
- frp穿透和ssl续期
- 宝塔安装
- 树莓派
- 浏览器模拟
- 火狐/chrome常用插件
- WSL安装使用
- mac brew和终端命令
- win10相关