#!/bin/bash
ip=$1
phone_no=$2
registerFrom=$3
namespace=$4
date=`date "+%Y-%m-%d %H:%M:%S"`

#"请输入用户手机号:" phone_no
len=`echo $phone_no|awk '{print length($0)}'`
if [ $len -ne 11 ];then
	echo "请输入11位手机号!"
	exit -1
fi

if [ -z "$registerFrom" ];then
	registerFrom=214
fi

cash_domain="qapi-$namespace.q-gp.com"
xyqb_domain="api-$namespace.q-gp.com"

if [ -z "$namespace" ];then
	cash_domain=$ip:7037
	xyqb_domain=$ip:7001
fi

#ip=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
resp=`curl "http://$cash_domain/app/login?registerFrom=$registerFrom&phoneNo=$phone_no" 2>/dev/null`
result=$(echo $resp | grep "成功")
if [ -n "$result" ];then
	token=`echo $resp | jq ".data.token" | sed "s/\"//g"`
	#echo "token: $token"
	echo "$date http://$xyqb_domain/app-landing?token=$token&registerFrom=$registerFrom&channelId=1"
else
	echo "获取token失败，请检查$ip的xyqb和cash-loan-flow"
fi
