多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 微信jssdk - 拉起卡券 > 所有需要微信jssdk中 拉起卡券的业务模块,只需在需分享页面</body>标签前使用 WechatIndex.php ~~~ 构建参数: $throw_wechat_card_params = [ 'appid'=>$this->wechat_account_info['authorizer_appid'], 'card_id'=>[ 'p_7k0xKFsNiPiJ31cEw7weu8FFzY' ] ]; 传递参数至模板引擎: return $this->fetch($this->addon_template.'/wechat_index/entry',[ 'throw_wechat_card_params'=>$throw_wechat_card_params, ]); ~~~ HTML ~~~ {:hook('throwWechatCard',$throw_wechat_card_params)} 此时底层会自动生成一个拉起卡券的方法,如下: function _add_wechat_card(success_callback,cancel_callback) { console.log(success_callback); wx.addCard({ cardList: card, success: function (res) { //成功领卡后回调 success_callback(res); }, cancel: function (res) { //取消后 回调 cancel_callback(res); } }); } 需要前端工程师编写回调函数。即 success_callback cancel_callback 接受参数为领卡或者取消领卡的返回值。 _add_wechat_card(success_callback,cancel_callback) 如: function success_callback(res){alert('666')} function cancel_callback(res){alert('666')} ~~~ #### 举例完整页面 ~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> entry <script> function alert() { console.log('sssss'); } </script> <button onclick="_add_wechat_card(alert,alert)">sss</button> <!--引入公共js类库--> <script src="{php} echo config('static_host');{/php}/common/jquery.min.js"></script> <!--引入第三方类库--> <script src="{php} echo config('static_host');{/php}/extend/layui/layui.js"></script> <!--引入模块js--> <script src="{php} echo config('static_host');{/php}/addon/{$addon_info['name']}/{$addon_setting['template']}/main.js"></script> {:hook('wechatJssdk',$wechat_jssdk_hook_params)} {:hook('shareWechatJssdk')} {:hook('throwWechatCard',$throw_wechat_card_params)} </body> </html> ~~~