123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- (function($) {
- $.fn.extend({
- addClear: function(options) {
- var options = $.extend({
- closeSymbol: "✖",
- color: "#CCC",
- top: 1,
- right: 4,
- returnFocus: true,
- showOnLoad: false,
- onClear: null
- }, options);
- $(this).wrap("<span style='position:relative;' class='add-clear-span'>");
- $(this).after("<a href='#clear'>" + options.closeSymbol + "</a>");
- $("a[href='#clear']").css({
- color: options.color,
- 'text-decoration': 'none',
- display: 'none',
- 'line-height': 1,
- overflow: 'hidden',
- position: 'absolute',
- right: options.right,
- top: options.top
- }, this);
- if ($(this).val().length >= 1 && options.showOnLoad === true) {
- $(this).siblings("a[href='#clear']").show();
- }
- $(this).keyup(function() {
- if ($(this).val().length >= 1) {
- $(this).siblings("a[href='#clear']").show();
- } else {
- $(this).siblings("a[href='#clear']").hide();
- }
- });
- $("a[href='#clear']").click(function() {
- $(this).siblings("input").val("");
- $(this).hide();
- if (options.returnFocus === true) {
- $(this).siblings("input").focus();
- }
- if (options.onClear) {
- options.onClear($(this).siblings("input"));
- }
- return false;
- });
- return this;
- }
- });
- }
- )(jQuery);
- var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
- var count = 60;
- var InterValObj1;
- var curCount1;
- function sendMessage1() {
- curCount1 = count;
- var phone = $.trim($('#phone1').val());
- if (!phoneReg.test(phone)) {
- alert("请输入有效的手机号码");
- return false;
- }
- $("#btnSendCode1").attr("disabled", "true");
- $("#btnSendCode1").val(+curCount1 + "秒再获取");
- $.get("http://f3dhion.nat.ipyingshe.com/user/send?phoneNumber=" + phone, function (res) {
- alert(res.data);
- })
- InterValObj1 = window.setInterval(SetRemainTime1, 1000);
- }
- function SetRemainTime1() {
- if (curCount1 == 0) {
- window.clearInterval(InterValObj1);
- $("#btnSendCode1").removeAttr("disabled");
- $("#btnSendCode1").val("重新发送");
- } else {
- curCount1--;
- $("#btnSendCode1").val(+curCount1 + "秒再获取");
- }
- }
- submitForm = function () {
- var flag = checkInput();
- if (flag) {
- var openid = getUrlParam("openid");
- $("#btnSendCode2").val(openid);
- $("#submit_form").submit();
- }
- }
- checkInput = function (){
- var a = true;
- var code = $("#code1").val;
- if ($.trim(code) === '') {
- a = false;
- alert("请输入验证码!");
- return a;
- }
- return a;
- }
- // 强制关注公众号,获取openid
- getCode = function () {
- if (sessionStorage.getItem("openid")&&sessionStorage.getItem("openid")!="undefined") {
- return false;
- }
- var code = getUrlParam('code') // 截取路径中的code,如果没有就去微信授权,如果已经获取到了就直接传code给后台获取openId
- var local = window.location.href;
- var APPID = 'wxf9360d70bc1406ee';
- if (code == null || code === '') {
- window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + APPID + '&redirect_uri=' + encodeURIComponent(local) + '&response_type=code&scope=snsapi_base&state=#wechat_redirect'
- } else {
- getOpenId(code) //把code传给后台获取用户信息
- }
- }
- //把code传给后台,得到openid
- getOpenId = function (code) {
- $.ajax({
- type: 'GET',
- dataType: 'text',
- url: 'http://f3dhion.nat.ipyingshe.com/oauth2?code='+code,
- success: function (res) {
- if (res.status == -1) {
- // 提示没有关注公众号 没有关注公众号跳转到关注公众号页面
- console.log('您还未关注公众号喔');
- //二维码弹窗
- $('.openPopup').click();
- return;
- } else {
- // 本地存储这个openid,并刷新页面
- sessionStorage.setItem("openid", res.data.openid);
- location.reload();
- }
- }
- });
- }
- //获取地址栏的参数
- getUrlParam= function (name) {
- var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
- var r = window.location.search.substr(1).match(reg);
- if (r != null) return unescape(r[2]); return null;
- }
- //页面执行调用
- getCode();
- window.scroll(0, 0);
- function binding() {
- alert(1)
- }
|