Commit d0173023 by sunchao

获取微信个人信息接口调试

parent 2a70ae39
......@@ -21,5 +21,6 @@
</div>
</div>
</div>
<div #payForm hidden></div>
import { Component, OnInit } from '@angular/core';
import { Component, OnInit , ElementRef, ViewChild} from '@angular/core';
import { MyService } from '../../my/my.service';
import { LifeCommonService } from '../../common/life-common.service';
@Component({
selector: 'ydlife-article-detail',
......@@ -6,12 +8,63 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./article-detail.component.scss']
})
export class ArticleDetailComponent implements OnInit {
@ViewChild('payForm') payForm: ElementRef;
articleInfo:any;
constructor() { }
lifeCustomerInfo:any;
paymentForm:any;
customerId:number;
constructor(private myService:MyService,public lifeCommonService:LifeCommonService) { }
ngOnInit() {
this.articleInfo =JSON.parse(sessionStorage.getItem('articleInfo'))
console.log(this.articleInfo)
this.articleInfo =JSON.parse(sessionStorage.getItem('articleInfo'));
this.lifeCustomerInfo = JSON.parse(localStorage.getItem('lifeCustomerInfo'))? JSON.parse(localStorage.getItem('lifeCustomerInfo')):null;
if(this.lifeCustomerInfo){
this.customerId = JSON.parse(localStorage.getItem('lifeCustomerInfo'))['customerId']
}else{
this.customerId = null;
}
if (this.lifeCommonService.checkDeviceType() == '3' && !this.customerId) {
this.getWxUserInfo();
}
}
// 从后台获取到获取微信code的URL
getWxUserInfo() {
this.myService.getWxUserInfo(this.customerId).subscribe(res => {
if (res['success']) {
this.paymentForm = res['data'].paymentForm;
alert(res['data']['userInfo']);
this.getOrPost(this.paymentForm.action, this.paymentForm.param, this.paymentForm.charset, this.paymentForm.actionType)
}
})
}
// 判断是get请求还是post请求进行支付请求
getOrPost(action, params, charset, actionType) {
let url = '';
let paramHTML = '';
let hiddenContent = '';
if (actionType.toLowerCase() === 'get') {
url = action;
if (params) {
for (let i = 0; i < params.length; i++) {
url += '&' + params[i].name + '=' + params[i].value;
}
}
window.location.href = url;
} else if (actionType.toLowerCase() === 'post') {
if (params) {
for (let i = 0; i < params.length; i++) {
paramHTML += '<input type="text" value="' + params[i].value + '" name="' + params[i].name + '" hidden>'
}
}
hiddenContent +=
'<form action="' + action + '"method="post" accept-charset="' + charset + '" onsubmit="document.charset=\'' + charset + '\';">'
+ paramHTML
+ '<button type="submit" id="submit" hidden></button>'
+ '</form>';
this.payForm.nativeElement.innerHTML = hiddenContent;
document.getElementById('submit').click();
}
}
}
......@@ -107,7 +107,7 @@ const myRoutes: Routes = [
{ path: 'suggestion',component:SuggestionComponent,data: [{ title: '问题反馈' }],canActivate:[AuthGuard]},
{ path: 'historical_rank', component: HistoricalRankComponent, canActivate: [AuthGuard] },
{ path: 'team_area',component:TeamAreaPanelComponent, canActivate: [AuthGuard]},
{ path: 'article', component:ArticleComponent,canActivate:[AuthGuard]},
{ path: 'article', component:ArticleComponent},
{ path: 'articleDetail',component:ArticleDetailComponent}
];
......
......@@ -606,4 +606,33 @@ export class MyService {
return res;
});
}
/**
* 获取微信用户的详细信息
*/
getWxUserInfo(customerId) {
const url = this.API + '/getWxUserInfo';
const cs = {
customerId: customerId
};
return this.http.post(url, cs).pipe((res)=>{
return res;
});
}
//保存文章code
articleShareCodeSave(param){
const url = this.ydapi + '/practitionerArticle/articleShareCodeSave';
return this.http.post(url, JSON.stringify(param)).pipe((res)=>{
return res;
});
}
//保存客户痕迹
articleTrackSave(param){
const url = this.ydapi + '/practitionerArticle/articleTrackSave';
return this.http.post(url, JSON.stringify(param)).pipe((res)=>{
return res;
});
}
}
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