1.域名(备案过的)
2.https证书
3.配置本地的nginx
4.本地安装server 服务器
https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html 进入微信公众平台,使用邮箱账号,选择注册小程序账号。一个邮箱只能注册一个类型的微信账号(订阅号、服务号、小程序)。 2.1、选择“云产品”—”域名服务“—”SSL证书管理",选择“申请证书(免费)”。若未认证,系统将提示进入系统认证 2.2、个人认证。 2.3、域名验证→域名验证指南 2.4、下载SSL证书。用于服务配置 自此,小程序成功通过https的方式与服务器进入连接。Table of Contents
一、注册微信小程序
二、搭建Https服务器
1、域名注册
2、SSL证书管理
3、服务器域名配置
a、将Http端口设置为默认的80端口,重定向端口设置为443(小程序服务器仅支持以上两个端口)。
b、小程序端发起HTTPS请求如下:Page({
onReady: function () {
wx.request({
url: 'https://weixin.techeek.cn/', //仅为示例,并非真实的接口地址
})
},
})
4、搭建第一个Https web server应用
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using System.Net;
using System.Text;
using Newtonsoft.Json;
using WeiXinThirdserver_Miniprogrom_nocloud.Models;
namespace WeiXinThirdserver_Miniprogrom_nocloud.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
string appid = "wxae737f";
string secret = "c5c88552529";
string code = "0a1LIq0w3Dra923GWq1w3fWI1z2LIq0O";
//AppID(小程序ID) wxae AppSecret(小程序密钥) c5c88552529
string cod = code;
string html = string.Empty;
string url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + appid + "&secret=" + secret + "&js_code=" + cod + "&grant_type=authorization_code";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "GET";
request.ContentType = "text/html;charset=UTF-8";
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream ioStream = response.GetResponseStream();
StreamReader sr = new StreamReader(ioStream, Encoding.UTF8);
html = sr.ReadToEnd();
sr.Close();
ioStream.Close();
response.Close();
RepParamrep rep = JsonConvert.DeserializeObject<RepParamrep>(html);
return View();
}
public IActionResult Privacy()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
public class RepParamrep
{
public string session_key { get; set; }
public string openid { get; set; }
}
}
@RequestMapping("/test") @ResponseBody public String test(){ return "hehe"; }
三、微信小程序访问服务器,并获取返回值
1、服务器配置