package api
import (
"encoding/json"
"encoding/xml"
"fmt"
"io/ioutil"
"net/http"
"strconv"
"strings"
"time"
"zhoujinhui/model"
"zhoujinhui/util"
"github.com/globalsign/mgo/bson"
)
const APPID, SECRET = "wxxxxxxxxxx86", "06xxxxxxxxxxx08"
const WX_LOGIN_API = "https://api.weixin.qq.com/sns/jscode2session?grant_type=authorization_code&appid=" + APPID + "&secret=" + SECRET
const MCH_ID, MCH_KEY, TRADE_TYPE = "1xxxxxx2", "34xxxxxxxxx87", "JSAPI"
const NOTIFY_URL, WX_PAY_API = "https://admin.qhx-xhx.com/api/notifyRrl", "https://api.mch.weixin.qq.com/pay/unifiedorder"
func GetOpenId(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
resp, err := http.Get(WX_LOGIN_API + "&js_code=" + r.Form.Get("res_code"))
defer resp.Body.Close()
if err == nil {
body, _ := ioutil.ReadAll(resp.Body)
var respStr = string(body)
var jm map[string]string
json.Unmarshal([]byte(respStr), &jm)
if jm["openid"] != "" {
if model.IsExistsWxUserByOpenId(jm["openid"]) {
model.EditWxUser(jm["openid"])
} else {
model.InsertWxUser(jm["openid"])
}
}
fmt.Fprint(w, respStr)
}
}
func UpdateUserInfo(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
openId := r.Form.Get("open_id")
if openId != "" {
var wxUser model.WU
json.Unmarshal([]byte(r.Form.Get("user_info")), &