Commit b5bd1be3 by 程默

同步

parent f62d8452
# mayi-app-shop
# mayi-mp-shop
> 商城小程序版本
......
......@@ -46,7 +46,8 @@ let baseWebpackConfig = {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue': 'mpvue',
'@': resolve('src')
'@': resolve('src'),
'@config':resolve('config')
},
symlinks: false,
aliasFields: ['mpvue', 'weapp', 'browser'],
......
......@@ -2,5 +2,7 @@ var merge = require('webpack-merge')
var prodEnv = require('./prod.env')
module.exports = merge(prodEnv, {
NODE_ENV: '"development"'
NODE_ENV: '"development"',
APPID:'"wx743dc2f4adb9cf01"',
OLSHOP_URL:'"https://dev-m-shop.mayi888.cn/innerApi/shopApiService"'
})
......@@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<title>mayi-app-shop</title>
<title>mayi-mp-shop</title>
</head>
<body>
<div id="app"></div>
......
{
"name": "mayi-app-shop",
"name": "mayi-mp-shop",
"version": "1.0.0",
"mpvueTemplateProjectVersion": "0.1.0",
"description": "商城小程序版本",
......
......@@ -19,8 +19,8 @@
},
"miniprogramRoot": "dist/wx/",
"compileType": "miniprogram",
"appid": "wxfe9889fb08e7f50b",
"projectname": "mayi-app-shop",
"appid": "wx743dc2f4adb9cf01",
"projectname": "mayi-mp-shop",
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {
......@@ -32,13 +32,24 @@
"current": -1,
"list": []
},
"plugin": {
"current": -1,
"list": []
},
"game": {
"currentL": -1,
"list": []
},
"miniprogram": {
"current": -1,
"list": []
"current": 0,
"list": [
{
"id": -1,
"name": "pages/logs/main",
"pathName": "pages/logs/main",
"scene": null
}
]
}
}
}
\ No newline at end of file
import {requestPOST,requestGET} from "@/utils/request.js";
console.log(process.env,'-----------------config------')
// wx
export default{
wxLoginCallback(params) {
return fetch(`${config.OLSHOP_URL}/wx/login_callback`, { params })
export default {
//登录
miniLogin(options){
return requestGET(`${process.env.OLSHOP_URL}/wx/mini_login`,options)
},
//绑定
bindUser(options){
return requestGET(`${process.env.OLSHOP_URL}/wx/mini_bind_user`,options)
}
}
\ No newline at end of file
......@@ -2,6 +2,8 @@ import request from "@/utils/request.js";
const baseApi = "http://test-m-shop.mayi888.cn/innerApi";
export function to_wx_pay(options){
return request(`${baseApi}/shopApiService/pay/to_wx_pay`,options)
}
\ No newline at end of file
export default {
to_wx_pay(options) {
return request(`${baseApi}/shopApiService/pay/to_wx_pay`, options)
}
}
\ No newline at end of file
{
"pages": [
"pages/index/main",
"pages/logs/main",
"pages/login/main",
"pages/wxPay/main",
"pages/counter/main"
],
......
<template>
<div @click="clickHandle">
12133
<web-view :src="link" @message="getMessage"></web-view>
<web-view :src="link+page+params" @message="getMessage"></web-view>
<!-- <div class="userinfo" @click="bindViewTap">
<img class="userinfo-avatar" v-if="userInfo.avatarUrl" :src="userInfo.avatarUrl" background-size="cover" />
<img class="userinfo-avatar" src="/static/images/user.png" background-size="cover" />
......@@ -10,7 +9,6 @@
<card :text="userInfo.nickName"></card>
</div>
</div>
+page+param
<div class="usermotto">
<div class="user-motto">
<card :text="motto"></card>
......@@ -30,59 +28,87 @@
</div>
<div class="right">
</div>
</div> -->
</div>-->
</div>
</template>
<script>
// import card from '@/components/card'
export default {
data () {
data() {
return {
link:'http://localhost:3000/?mixid=dev001',
page:'',
param:"?mixid=dev001",
motto: 'Hello miniprograme',
session_key: "",
link: "http://localhost:3000",
page: "",
params: "?mixid=dev001&",
motto: "Hello miniprograme",
userInfo: {
nickName: 'mpvue',
avatarUrl: 'http://mpvue.com/assets/logo.png'
nickName: "mpvue",
avatarUrl: "http://mpvue.com/assets/logo.png"
}
}
};
},
onLoad(option){
console.log(option,'index');
// if (option.payCallback && option.orderSn) {//支付页面跳转过来
// this.page=option.payCallback;
// this.param=this.param+'&orderSn='+option.orderSn;
// this.link=link
// }
onShareAppMessage() {
return {
title: "微信小程序",
desc: "小程序开发!",
path: "/page/logs"
};
},
onLoad(options) {
console.log(options, "index");
this.initData();
if (options.from=='login') {
this.page=decodeURIComponent(options.backpath);
this.params+=decodeURIComponent(options.params);
} else if (options.from=='wxPay') {
}
return
if (options.payCallback && options.orderSn) {
//支付页面跳转过来
this.page = options.payCallback;
this.params = this.params + "&orderSn=" + options.orderSn;
} else if (options.scene) {//扫码
// options 中的scene需要使用decodeURIComponent才能获取到生成二维码时传入的scene
var scene = decodeURIComponent(options.scene); //参数二维码传递过来的参数
var query = options.query.dentistId; // 参数二维码传递过来的场景参数
}else if(options){
}
},
components: {
// card
},
methods: {
bindViewTap () {
const url = '../logs/main'
if (mpvuePlatform === 'wx') {
mpvue.switchTab({ url })
initData(){
this.page="";
this.params="?mixid=dev001&";
},
bindViewTap() {
const url = "../logs/main";
if (mpvuePlatform === "wx") {
mpvue.switchTab({ url });
} else {
mpvue.navigateTo({ url })
mpvue.navigateTo({ url });
}
},
clickHandle (ev) {
console.log('clickHandle:', ev)
clickHandle(ev) {
// console.log("clickHandle:", ev);
// throw {message: 'custom test'}
},
getMessage(res){
console.log('h5消息')
getMessage(res) {
console.log("h5消息");
}
},
created () {
created() {
// let app = getApp()
}
}
};
</script>
<style scoped>
......@@ -113,27 +139,27 @@ export default {
margin-bottom: 5px;
border: 1px solid #ccc;
}
.all{
width:7.5rem;
height:1rem;
background-color:blue;
.all {
width: 7.5rem;
height: 1rem;
background-color: blue;
}
.all:after{
display:block;
content:'';
clear:both;
.all:after {
display: block;
content: "";
clear: both;
}
.left{
float:left;
width:3rem;
height:1rem;
background-color:red;
.left {
float: left;
width: 3rem;
height: 1rem;
background-color: red;
}
.right{
float:left;
width:4.5rem;
height:1rem;
background-color:green;
.right {
float: left;
width: 4.5rem;
height: 1rem;
background-color: green;
}
</style>
<template>
<div class="domain">
<button
v-if="getPhone"
open-type="getPhoneNumber"
@getphonenumber="getPhoneNumber"
class="login"
>微信手机号快捷登录</button>
<div v-else>
<mp-loading
:duration="900"
ext-class="demo0"
type="dot-gray"
:show="show"
:animated="animated"
>加载中</mp-loading>
</div>
</div>
</template>
<script>
import { serialize } from "@/utils/index";
import { wx_decode } from "@/utils/wxIndex.js";
import login from "@/api/login";
var WXBizDataCrypt = require("@/utils/WXBizDataCrypt");
export default {
components: {
// card
},
data() {
return {
getPhone: false,
openid: "",
phoneNumber: "",
logs: [],
tips: "请稍后",
show: true,
animated: true,
backPath: "",
backParams: ""
};
},
created() {},
onLoad(options) {
if (options.back) {
this.backPath = options.back;
}
if (options.params) {
this.backParams = serialize(options.params);
}
console.log(options, "登录页面", this.backPath, this.backParams);
this.init();
},
methods: {
init() {
wx.login({
success: res => {
if (res.code) {
login
.miniLogin({ code: res.code })
.then(res => {
console.log(res);
if (res.data.code == 200) {
if (res.data.data.isHaveUnion == "true") {
//有账号
wx.setStorage({
key: "sessionId",
data: res.data.data.sessionId
});
wx.redirectTo({
url: `../index/main?from=login&backpath=${
this.backPath
}&params=${this.backParams}`
});
} else {
//需要绑定
this.getPhone = true;
this.openid = res.data.data.openid;
}
this.session_key = res.data.data.session_key;
}
})
.catch(err => {});
}
}
});
},
getPhoneNumber(e) {
wx.checkSession({
success: () => {
//session_key 未过期,并且在本生命周期一直有效
if (e.target.errMsg == "getPhoneNumber:ok") {
this.phoneNumber = wx_decode(
process.env.APPID,
this.session_key,
e.mp.detail.encryptedData,
e.mp.detail.iv + ""
).phoneNumber;
this.bindUser();
console.log(this.phoneNumber, "daadadadad");
} else if (e.target.errMsg == "getPhoneNumber:fail user deny") {
console.log("用户取消", this.backParams);
wx.redirectTo({
url: `../index/main?from=login&backpath=${this.backPath}&params=${
encodeURIComponent(this.backParams)
}`
});
} else {
}
},
fail: () => {
// session_key 已经失效,需要重新执行登录流程
// wx.login() //重新登录
}
});
},
bindUser() {
login
.bindUser({
openId: this.openid,
phoneNumber: this.phoneNumber
})
.then(res => {
//登录成功
console.log(res, "binduser");
wx.setStorage({
key: "sessionId",
data: res.data.data.sessionId
});
})
.catch(err => {
console.log(err, "bindusererr");
});
}
}
};
</script>
<style>
.login {
background-color: green;
margin: 30px;
color: #fff;
}
</style>
<template>
<div>
<swiper v-if="imgUrls.length > 0" indidator-dots="imgUrls.length > 1" >
<block v-for="(item, index) in imgUrls" :key="index" >
<swiper-item>
<image :src="item" mode="scaleToFill"></image>
</swiper-item>
</block>
</swiper>
<ul class="container log-list">
<li v-for="(log, index) in logs" :class="{ red: aa }" :key="index" class="log-item">
<card :text="(index + 1) + ' . ' + log"></card>
</li>
</ul>
</div>
</template>
<script>
import { formatTime } from '@/utils/index'
import card from '@/components/card'
export default {
components: {
card
},
data () {
return {
logs: [],
imgUrls: [
'http://mss.sankuai.com/v1/mss_51a7233366a4427fa6132a6ce72dbe54/newsPicture/05558951-de60-49fb-b674-dd906c8897a6',
'http://mss.sankuai.com/v1/mss_51a7233366a4427fa6132a6ce72dbe54/coursePicture/0fbcfdf7-0040-4692-8f84-78bb21f3395d',
'http://mss.sankuai.com/v1/mss_51a7233366a4427fa6132a6ce72dbe54/management-school-picture/7683b32e-4e44-4b2f-9c03-c21f34320870'
]
}
},
created () {
let logs
if (mpvuePlatform === 'my') {
logs = mpvue.getStorageSync({key: 'logs'}).data || []
} else {
logs = mpvue.getStorageSync('logs') || []
}
this.logs = logs.map(log => formatTime(new Date(log)))
}
}
</script>
<style>
.log-list {
display: flex;
flex-direction: column;
padding: 40rpx;
}
.log-item {
margin: 10rpx;
}
</style>
......@@ -49,6 +49,9 @@ export default {
success: function(res) {
console.log(res, "ressssssss");
let payData = JSON.parse(res.data.data);
payData.appId='wxfe9889fb08e7f50b';
console.log(res, "ressssssss");
// {
// timestamp: 0, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
// nonceStr: '', // 支付签名随机串,不长于 32 位
......@@ -59,7 +62,7 @@ export default {
// }
payData.success = res => {
console.log("支付成功", res);
wx.redirectTo({"url":`../index/main?payCallback=/pay/paySuccess&orderSn=${options.orderSn}`});
// wx.redirectTo({"url":`../index/main?payCallback=/pay/paySuccess&orderSn=${options.orderSn}`});
// Toast("支付成功~");
// window.location.replace('/pay/paySuccess?orderSn='+this.$route.query.orderSn);
// this.$router.replace(
......@@ -76,14 +79,13 @@ export default {
};
payData.complete = res => {
console.log("支付取消", res,options);
wx.redirectTo({"url":`../index/main?payCallback=/pay/paySuccess&orderSn=${options.orderSn}`});
wx.redirectTo({"url":`../index/main?from=wxPay&backpath=/pay/paySuccess&params=${options.orderSn}`});
if (res.errMsg == "chooseWXPay:cancel") {
console.log("支付取消11");
// payApi.cancelPayment(this.$route.query.orderSn);
}
};
wx.requestPayment(payData);
return;
// wx.navigateTo({
// url: `/pages/lnyc2019/detail?ordercode=${self.data.ordercode}`
// });
......
var crypto = require('crypto')
function WXBizDataCrypt(appId, sessionKey) {
this.appId = appId
this.sessionKey = sessionKey
}
console.log('-------------',crypto)
WXBizDataCrypt.prototype.decryptData = function (encryptedData, iv) {
// base64 decode
var sessionKey = new Buffer(this.sessionKey, 'base64')
encryptedData = new Buffer(encryptedData, 'base64')
iv = new Buffer(iv, 'base64')
// try {
// 解密
var decipher = crypto.createDecipheriv('aes-128-cbc', sessionKey, iv)
// console.log('-------------',decipher)
// 设置自动 padding 为 true,删除填充补位
decipher.setAutoPadding(true)
var decoded = decipher.update(encryptedData, 'binary', 'utf8')
decoded += decipher.final('utf8')
decoded = JSON.parse(decoded)
// } catch (err) {
// throw new Error('Illegal Buffer')
// }
if (decoded.watermark.appid !== this.appId) {
throw new Error('Illegal Buffer')
}
return decoded
}
module.exports = WXBizDataCrypt
function formatNumber (n) {
function formatNumber(n) {
const str = n.toString()
return str[1] ? str : `0${str}`
}
//格式时间
export function formatTime (date) {
export function formatTime(date) {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
......@@ -19,6 +19,18 @@ export function formatTime (date) {
return `${t1} ${t2}`
}
//对象转querystring
export function serialize(obj) {
var str = [];
obj = JSON.parse(obj);
for (var p in obj) {
if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
}
return str.join("&");
}
export default {
formatNumber,
formatTime
......
export function requestGET(url, options) {
return new Promise((resolve, reject) => {
wx.request({
url: url,
data: options,
method: "GET",
header: {
"Content-Type": "application/x-www-form-urlencoded",
"Shop-Mixid": "dev001",
Authorization: "ce9d0ca7-ba9b-4951-9c42-47cd9b5e4f42"
},
success: function (res) {
resolve(res)
},
fail: function (res) {
reject(res)
}
})
})
}
export function request(url, options) {
export function requestPOST(url, options) {
return new Promise((resolve, reject) => {
wx.request({
url: url,
data: options,
method: "POST",
header: {
"Content-Type": "application/x-www-form-urlencoded",
"Shop-Mixid": "dev001",
Authorization: "ce9d0ca7-ba9b-4951-9c42-47cd9b5e4f42"
},
......
// 微信解密
export function wx_decode(appId,sessionKey,encryptedData,iv) {
var WXBizDataCrypt = require('./WXBizDataCrypt');
var pc = new WXBizDataCrypt(appId, sessionKey);
var data = pc.decryptData(encryptedData, iv);
return data;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment