ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 微信公众号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> ``` ```