如何在本机上利用IIS网页发布实现微信小程序与数据库之间的通信
主要思想:
下面就login(登录)部分做出方案
- 微信小程序
首先要构建一个界面和逻辑模式
WXML部分:
<!--pages/login/login.wxml--><!--<view style="height:300rpx"></view><view class="Box">账号:<input class="in" type="text" bindinput="getNum"/></view><view class="Box"> 密码:<input class="in" type="text" bindinput="getPasswd"/></view><button>登录</button>--><view class="container"><view class="userinfo"><block wx:if="{{canIUseOpenData}}" calss="userinfo-opendata"><view class="userinfo-avatar" bindtap="bindViewTap"><open-data type="userAvatarUrl"></open-data></view><open-data type="userNickName"></open-data></block><block wx:elif="{{!hasUserInfo}}"><button wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile"> 获取头像昵称 </button><button wx:elif="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button><view wx:else> 请使用1.4.4及以上版本基础库 </view></block><block wx:else><image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image><text class="userinfo-nickname">{{userInfo.nickName}}</text></block></view><form bindsubmit="formSubmit" bindreset="formReset"><view class="login-icon"></view><view class="login-from"><!--账号--><view class="inputView"><text class="iconfont icon-yonghuming" style="margin-left: 44rpx; "></text><input class="inputText" placeholder="请输入账号" bindinput="usernameInput" /></view><!--密码--><view class="inputView"><text class="iconfont icon-mima" style="margin-left: 44rpx; "></text><input class="inputText" password="true" placeholder="请输入密码" bindinput="passwordInput" /></view><!--按钮--><view class="loginBtnView"><button class="loginBtn" type="primary" size="{{primarySize}}" loading="{{loading}}" plain="{{plain}}" disabled="{{disabled}}" bindtap="login">登录(Login)</button></view></view></form></view>
WXSS部分
/* pages/login/login.wxss */.inputText{height: 50rpx;width: 650rpx;border-style: solid;border-color: #000;border-radius: 650px;padding-left: 10rpx;background-color: #fff;}.loginBtn{margin-left: 80rpx;text-align: center;margin-top: 40rpx;}.SignInView{text-align: right;margin-top: 20rpx;margin-left: 450rpx;color:#cccccc;}.userinfo {display: flex;flex-direction: column;align-items: center;margin-top: 30rpx;color:#000;}.userinfo-avatar {overflow: hidden;width: 256rpx;height: 256rpx;margin-top: -20rpx;border-radius: 25%;}.usermotto {margin-top: 200px;}Page{background-color: #0094aa;}
这两个完成后,刷新,页面应该如下图(黑色部分为微信图像和昵称,在这里就不做演示)
JS部分
const app = getApp()Page({data: {motto: 'Hello World',userInfo: {},hasUserInfo: false,canIUse: wx.canIUse('button.open-type.getUserInfo'),canIUseGetUserProfile: false,canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false},onLoad() {if (wx.getUserProfile) {this.setData({canIUseGetUserProfile: true})}},getUserProfile(e) {// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗wx.getUserProfile({desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写success: (res) => {console.log(res)this.setData({userInfo: res.userInfo,hasUserInfo: true})}})},getUserInfo(e) {// 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息console.log(e)this.setData({userInfo: e.detail.userInfo,hasUserInfo: true})},usernameInput: function(e) {this.setData({username: e.detail.value})},passwordInput: function (e) {this.setData({password: e.detail.value})},login: function () {wx.request({url: app.globalData.globalReqUrl+"/Login.asmx/logincheck",//后端的url地址data: {//传给后端的数据user:this.data.username,password:this.data.password,},method: 'post',success: function (res) {//res为从后端获取的数据console.log(res.data);if (res.data.d == "ok") {wx.switchTab({url: '../home/home'})}else{wx.showToast({title: '账号或密码错误!',icon:"none",duration:2000})wx.navigateTo({url: '../index/index'})}},fail: function (res) {wx.showToast({title: '连接服务器失败!',icon:"none",duration:2000})}})}})
以上就是微信小程序要做的工作,下面开始准备在电脑上加入IIS
详见https://jingyan.baidu.com/article/6079ad0eb37aac28fe86db6a.html
切记电脑更新一定要打开!
中间语言部分
首先,要加载LinQ的插件,方便中间和数据库连接,创建ASP.NET Web应用程序
在图中添加新项中添加LinQ to SQL组件
然后将Web服务添加其中
在Web服务中添加以下代码
中间语言C#
这里用的是VS2019进行编译和连接using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Services;using System.Text;using System.Threading.Tasks;using System.Data; //引用 表的命名空间using System.Data.SqlClient;namespace Link0CS0{/// <summary>/// WebService1 的摘要说明/// </summary>[WebService(Namespace = "http://tempuri.org/")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)][System.ComponentModel.ToolboxItem(false)]// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。[System.Web.Script.Services.ScriptService]public class WebService1 : System.Web.Services.WebService{[WebMethod]public string HelloWorld(){return "Hello World";}[WebMethod]public string logincheck(string user, string password){//String Num, Passwd;DataClasses1DataContext db = new DataClasses1DataContext();//db.User_tableint UserNum = db.login1(user, password);//linqDataContext db = new linqDataContext()//int ii = db.proc_select_login1(user, 0);if (UserNum>=1){return "ok";}else{return "no";}}}}
做好后就可以发布网页
如图即可发布网页
}
在浏览器输入IP后
得到以上网页就说明发布成功
在后面加上前面添加的Web服务添加在后面
如192.0.0.1+“/Login.asmx”
回车进入以下界面
与直接在编译器中运行一致
此时中间语言部分基本完成
中间语言完成后就可以连接数据库只需输入电脑的名称或IP即可,不再过多赘述
数据连接,还是按照上面的步骤依次填写就好,不再过多赘述。
SQL数据库部分
数据库和存储过程
create Table User_table(Num varchar(15),Constraint User_tablePKKey primary key(Num),Passwd varchar(20),)create procedure login1(@userNum varchar(15) = null,@userPasswd varchar(20) = null)asbeginset nocount ondeclare @n intselect @n=count(*) from User_table where Num=@userNum and Passwd=@userPasswdreturn @nend
中间语言与SQL数据库的通信
点开LinQ类中,将数据库的表和存储过程拖入其中,即可完成连接
微信小程序与中间语言的通信
在微信小程序中app.js
改成以下代码
// app.jsApp({onLaunch() {// 展示本地存储能力const logs = wx.getStorageSync('logs') || []logs.unshift(Date.now())wx.setStorageSync('logs', logs)// 登录wx.login({success: res => {// 发送 res.code 到后台换取 openId, sessionKey, unionId}})},globalData: {userInfo: null,globalReqUrl:"http://192.168.10.1"}})
特别强调globalReqUrl换成自己的发布时的IP
向数据库中添加用户
在微信小程序中验证
即可跳转到你设置的页面
此时,所有的工作已经完成,微信小程序和数据库已经可以通信,本次实验完毕
如何在本机上利用IIS网页发布实现微信小程序与数据库之间的通信相关推荐
- nodejs android 推送,利用Nodejs怎么实现一个微信小程序消息推送功能
利用Nodejs怎么实现一个微信小程序消息推送功能 发布时间:2021-01-20 13:55:29 来源:亿速云 阅读:92 作者:Leah 今天就跟大家聊聊有关利用Nodejs怎么实现一个微信小程 ...
- 利用WordPress REST API 开发微信小程序从入门到放弃
自从我发布并开源WordPress版微信小程序以来,很多WordPress网站的站长问有关程序开发的问题,其实在文章:<用微信小程序连接WordPress网站>讲述过一些基本的要点,不过仍 ...
- h5网页跳转微信小程序
H5网页跳转微信小程序 再次记录下, 通过使用微信开放标签,可便捷的跳转到微信小程序. 文章目录 H5网页跳转微信小程序 效果图 一.小程序跳转按钮 二.开放标签使用步骤 1. 绑定域名 2. 引入j ...
- 网页js打开微信小程序示例
1. 引入js,script方式引入SDK云函数: 下载:网页js打开微信小程序js-SDK-Node.js文档类资源-CSDN下载 2. 填写APP ID,封装调用函数: async functio ...
- 微信小程序开发笔记 进阶篇③——onfire.js事件订阅和发布在微信小程序中的使用
文章目录 一.前言 二.onfire.js介绍 三.API介绍 四.实例应用 五.onfire源码 六.实例源码 一.前言 微信小程序开发笔记--导读 二.onfire.js介绍 一个简单实用的事件订 ...
- 将网页代码转换成微信小程序代码
如果你想要把你的网页代码转换成小程序代码,你有以下几种方法: 使用一种叫做 H5 to 小程序 的在线工具,可以将 H5 网页转换为微信小程序项目.你只需要在网站上传你的 H5 网页文件,或者将 H5 ...
- CocosCreator上的游戏(调试)发布到微信小程序
1.下载CocosCreator,微信开发者工具 官网地址:http://www.cocos.com/download 官网下载:https://developers.weixin.qq.com/mi ...
- WordPress版微信小程序2.6版发布
WordPress版微信小程序的完善和升级的工作一直都在进行中,我争取保证一个月可以出一个版本,希望通过一点点的改进,让这个开源产品日趋完美. 同时,pro版WordPress微信小程序也在紧锣密鼓的 ...
- 微信小程序首支视频广告片发布
自2017年1月9日上线以来,微信小程序瞬间引爆网络,又迅速归于平静.对这个"无需安装.触手可及.用完即走.无需卸载"的小程序,微信从一开始就对它寄予了无限期望.在公布一系列规则更 ...
最新文章
- 数据预处理+缺失值处理方案+Missing Value+pandas+缺失值填充方法、方案
- Nginx错误日志说明
- 讯飞输入法皮肤制作_手机输入法哪家强:百度、搜狗、讯飞输入法对比评测
- Java 反射修改类的常量值、静态变量值、属性值
- Java版 QQ空间自动登录无需拷贝cookie一天抓取30WQQ说说数据流程分析【转】
- elasticsearch手动创建和删除索引
- VTK:折线用法实战
- P4590 [TJOI2018]游园会 dp套dp + 状态机
- java vector 输出_5.7(java学习笔记)Vector、Enumeration
- MVC3 Razor语法速查
- java实验 输入输出_实验十三 Java输入输出(一)
- 微信小程序开发工具_云函数本地调试的依赖下载安装情况查看/云函数本地调试基础/调试手段和技巧
- mysql rownum写法_mysql类似oracle rownum写法实例详解
- 少说话多写代码之Python学习022——赋值语句01(序列解包)
- 需求开发应用部署“一条龙”,平安云如何加速容器场景落地
- 投入OJ的怀抱~~~~~~~~~~
- 自动摘要生成 tf-idf+doc2vec+句子聚类
- python0为真还是假_python 中对象真和假的概念是什么
- Excel原封不动导入txt文件
- 2022-10-28: 测试代码流程